However, I cannot find a way to control the timezone the
DateTimeFormat class uses when formatting dates:
On my client:
DateTimeFormat fmt = DateTimeFormat.getFormat("dd.MM.yyyy HH:mm:ss
z");
fmt.format(myDate) --> 11.08.1973 01:00:00 GMT+01:00
How can I format the date so that I get
11.08.1973 00:00:00 GMT+00:00 instead??
The dateTimeFormat class obviously supports timezones, but how can I
control it?
Regards,
Karl Ivar Dahl
DateTimeFormat fmt = DateTimeFormat.getFormat("dd.MM.yyyy HH:mm:ss");
label.setText(fmt.format(d) + " GMT+00:00");
regards,
Peter
I have tested this now, and it turns out that while removing the "z"
removes the "GMT+01:00" part of the output, the date is still
presented in GMT+1 (one hour off).
DateTimeFormat fmt = DateTimeFormat.getFormat("dd.MM.yyyy HH:mm:ss");
fmt.format(myDate) --> 11.08.1973 01:00:00
The incoming date is actually 11.08.1973 00:00:00 GMT+0
There must be a way to tell the formatter that it should present the
date in GMT+0?
Does anyone know how GWT aquires the client timezone used for this
formatting?
-Karl Ivar
On Oct 12, 3:17 am, Peter Blazejewicz <peter.blazejew...@gmail.com>
wrote:
package com.mycompany.project.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import java.util.Date;
public class TestDateModule implements EntryPoint {
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
Date d = new Date();
// gwt
rootPanel.add(new Label("GWT date object"));
rootPanel.add(new Label("toLocaleString: " + d.toLocaleString()));
rootPanel.add(new Label("toGMTString: " + d.toGMTString()));
rootPanel.add(new Label("toString: " + d.toString()));
// native
JavaScriptObject jsd = getDate();
rootPanel.add(new Label("JavaScript object"));
rootPanel.add(new Label("toLocaleString: " +
dateToLocaleString(jsd)));
rootPanel.add(new Label("toGMTString: " + dateToGMTString(jsd)));
rootPanel.add(new Label("toUTCString: " + dateToUTCString(jsd)));
rootPanel.add(new Label("toString: " + dateToString(jsd)));
}
private static native JavaScriptObject getDate()/*-{
return new Date();
}-*/;
private static native String dateToLocaleString(JavaScriptObject
date)/*-{
return date.toLocaleString();
}-*/;
private static native String dateToGMTString(JavaScriptObject date)/
*-{
return date.toGMTString();
}-*/;
private static native String dateToUTCString(JavaScriptObject date)/
*-{
return date.toUTCString();
}-*/;
private static native String dateToString(JavaScriptObject date)/*-{
return date.toString();
}-*/;
}
GWT date object
toLocaleString: 2007-10-17 15:20:05
toGMTString: 17 Oct 2007 13:20:05 GMT
toString: Wed Oct 17 15:20:05 CEST 2007
JavaScript object
toLocaleString: 17 October 2007 15:20:05
toGMTString: Wed, 17 Oct 2007 13:20:05 UTC
toUTCString: Wed, 17 Oct 2007 13:20:05 UTC
toString: Wed Oct 17 15:20:05 UTC+0200 2007
I guess GWT formatter takes offset from native object somehow and show
it in java compatible way,
regards,
Peter