0

I am storing timezone value in database as +5:30 or +2:00 or -1:00

I am fetching data from database and changing time according to time zone in java.

Here I would like to know how can I get time according to saved timezone value.

xrcwrn
  • 5,339
  • 17
  • 68
  • 129
  • 3
    Possible answer present at http://stackoverflow.com/questions/9429357/date-and-time-conversion-to-some-other-timezone-in-java – Naman Gala Nov 19 '14 at 11:37

3 Answers3

0

Use Timezone and Calendar. And check SO before asking...

Examples here, or here

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
0
TimeZone tz = Calendar.getInstance().getTimeZone();
System.out.println(tz.getDisplayName());// (i.e. Moscow Standard Time)
System.out.println(tz.getID()); 

That should get the time zone that the computer the user is using has been set to.

Unless you want to use a complicated solution by pinging a server and making a server-side check to see where the IP came from, then that is the closest you're going to get.

Joehot200
  • 1,070
  • 15
  • 44
0

Use SimpleDateFormat and setTimeZone

String timeZone = "GMT" + offset // offset is the value you store in the db( +5:30, -2:30)

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone(timeZone));
Date date = format.parse("2014-11-19T09:01:02");