In some cases, we always want to show the current date and time while adding new order or item, etc in the screen. Here is an example for the same.
Assume that you have the Hibernate POJO as follows
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Temporal(TemporalType.DATE)
private Date collectedDate;
private Time collectedTime;
public Date getCollectedDate() {
return collectedDate;
}
public void setCollectedDate(Date collectedDate) {
this.collectedDate = collectedDate;
}
public Time getCollectedTime() {
return collectedTime;
}
public void setCollectedTime(Time collectedTime) {
this.collectedTime = collectedTime;
}
Now you can use the following statement to set current date and time
this.selectedOrder.setCollectedDate(new Date());
this.selectedOrder.setCollectedTime(new java.sql.Time(System
.currentTimeMillis()));