Reputation: 571
My application is hosted at one place whose Timezone is "A". And user can login from anywhere. Let's say he/she logged in from place whose timezone "B". I want the timezone of User from where he/she get logged in. So I can display him dates in his/her timezone.
So is there any way to get that user's timezone?
Upvotes: 3
Views: 8144
Reputation: 315
A way to retrieve the client's timezone is to use javascript code through a native JNI method, as following:
private native int getClientOffsetTimeZone() /*-{
return new Date().getTimezoneOffset();
}-*/;
Note that the getTimezoneOffset() method returns the time difference between UTC time and local time, in minutes.
For example, If your time zone is GMT+2, -120 will be returned.
Upvotes: 2
Reputation: 91
From client, you can retrieve the timezone offset with Date.getTimezoneOffset()
and pass it to your server then use this offset to create correct Dates.
Upvotes: 0
Reputation: 615
GWT has the com.google.gwt.core.client.JsDate
library, which is a wrapper to the JSNI that Yeser mentioned. That library exposes the native JavaScript Date object, which allows you to use getTimezoneOffset()
.
Upvotes: 1