how can I get a GMT date time in java ?

8 views
Skip to first unread message

Lei

unread,
May 6, 2013, 5:14:05 PM5/6/13
to programmin...@googlegroups.com
When I create a new Date object, it is initialized to the current time but in the local timezone. How can I get the current date and time in GMT?

Lei

unread,
May 6, 2013, 5:14:24 PM5/6/13
to programmin...@googlegroups.com
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));

//Local time zone   
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");

//Time in GMT
return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
Reply all
Reply to author
Forward
0 new messages