Tuesday, May 4, 2010

How do I – Java: get current date/time in UTC format

To get date/time in UTC format you’ll need two classes java.text.SimpleDateFormat and java.util.TimeZone.

Create an instance of the SimpleDateFormat passing a desired format and set a time zone for it (by calling TimeZone.getTimeZone with “UTC” value).


SimpleDateFormat formatUTC = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ssZ");


return formatUTC.format(new Date());

Note: Using “GMT” time zone you can get time in GMT format.

No comments :

Post a Comment