Syntax about date in java

Syntax :

// cek datetime sesuai format dd/MM/yyyy

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/dd”);


//Convert string to date

Date dateTime = sdf.parse(dateTimeString);


//Convert date to string

String dateTimeString = sdf.format(dateTime);


//Print datetimeString



//Function StringtoDate

Note : I’ll use this function when I take some data in Database using hibernate framework. After that, I’ll convert the data from date type into string type in Spring framework then I’ll send it to Struts2 framework.

private String toDate(Object obj, String dateformat){

String s = (null != obj) ? new SimpleDateFormat(dateformat).format(obj) : null;

return s;



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s