Pl help me. I'm saving the date in UTC format. while displaying it, i'm converting it to local time. but it is displaying server time. How can i display the date by identifying the client timezone?using java
Asked
Active
Viewed 282 times
-2
-
2Is it a web app or a heavy client? – C.Champagne Jul 02 '13 at 07:46
-
1Will it help? http://stackoverflow.com/a/3001294/1862502 – Vignesh Vino Jul 02 '13 at 07:47
-
For better help sooner, post your code as an [SSCCE](http://www.sscce.org) that demonstrates your problem. This allows users to copy/paste and reproduce your issue. – Duncan Jones Jul 02 '13 at 07:50
2 Answers
3
The HTTP protocol provides no means to obtain the client's time zone. What applications usually do is allow the user to set the timezone in their profile or preferences. They might use geolocation based on the user's IP to get an initial guess but that's not really reliable, or use a piece of JavaScript code if client-side scripts can be used.
If JavaScript can work for you, this library seems easy to use and reasonably robust: http://pellepim.bitbucket.org/jstz/

Joni
- 108,737
- 14
- 143
- 193
0
try this:
int offset = TimeZone.getDefault().getRawOffset() +
(Calendar.getInstance().getTimeZone().inDaylightTime(yourDate) ? TimeZone.getDefault().getDSTSavings() : 0);
yourDate.setTime(yourDate.getTime() + offset);
it works for me hope it works for you.
P.S. this Codes should be on the client side after getting the date in UTC you convert it to the client Local Time

Tarek K. Ajaj
- 2,461
- 1
- 19
- 24