-2

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

2 Answers2

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