开发者

How can I get the time in GMT using GWT?

开发者 https://www.devze.com 2023-02-18 19:23 出处:网络
I want to get the current time of the machine in GMT and presented it on custom format like this one using GWT:

I want to get the current time of the machine in GMT and presented it on custom format like this one using GWT:

 yyyyMMddHHmmss

How I can achieve that?

I've tried this, but I didn开发者_如何学Go't find how can I present this local time in GMT:

Date date = new Date();
DateTimeFormat dtf = DateTimeFormat.getFormat("yyyyMMddHHmmss");
System.err.println(dtf.format(date).toString());

Also note that the Date.getTimezoneOffset() is deprecated, which I could use to subtract it from the current date and format it afterwards, but it doesn't sound like a good plan.


Date date = new Date();
DateTimeFormat dtf = DateTimeFormat.getFormat("yyyyMMddHHmmss");
Window.alert(dtf.format(date, TimeZone.createTimeZone(0)));

You need to import com.google.gwt.i18n.client.TimeZone and not java.util.TimeZone.

0

精彩评论

暂无评论...
验证码 换一张
取 消