Thursday, December 10, 2009

Simple way to display current Timestamp using Java

String timeStamp()
java.util.Calendar calendar = java.util.Calendar.getInstance();
return (new java.text.SimpleDateFormat("yyyyMMddHHmm").format(calendar.getTime()));

Consider today's date is Dec 10, 2009 and the time is half passed five in the morning then the above code will return 200912100530 as output.

Refer SimpleDateForamt API for more display customization.


Post a Comment