Wednesday, 21 August 2013

How to get Current Date and Time and store in the bean

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;

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

No comments:

Post a Comment

Passing Parameter between two files using MVVM

This examples shows how to pass parameter between two zul screens. In this example, we are passing some parameters from the parent vm to...