开发者

Getting a GWT timestamp in UTC format

开发者 https://www.devze.com 2023-01-28 10:08 出处:网络
I am trying to get the current timestamp and convert it into a UTC date for an XML file. I am using this

I am trying to get the current timestamp and convert it into a UTC date for an XML file.

I am using this

import java.util.Date;
import java.util.TimeZone;
import com.google.gwt.i18n.cl开发者_运维技巧ient.DateTimeFormat;

DateTimeFormat.format( new Date(), TimeZone.getTimeZone("UTC"));

but am getting the following error

The method format(Date, TimeZone) in the type DateTimeFormat is not applicable for the arguments (Date, TimeZone)

I need the output as "yyyy-mm-ddThh:mm:ssZ"


Use com.google.gwt.i18n.client.TimeZone.createTimeZone(0) to create a UTC TimeZone object, and then use that in DateTimeFormat.format(Date, TimeZone).


You can use apostrophe to indicate literals in a DateTimeFormat pattern. eg. "HH'o''clock'"

So, the formatter you need would look something like this:

DateTimeFormat formatter = DateTimeFormat.getFormat("yyyy-mm-dd'T'HH:mm:ssZ");

I tried it out. It gave me an output in format 2010-16-29T08:16:23+0530

Is this what you are looking for?


You should provide a com.google.gwt.i18n.client.TimeZone instead of java.util.TimeZone

0

精彩评论

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