I am developing a software in java.
I get a timestamp in GMT from a server. The software can be used anywhere in the world. Now I want to get the local time zone where the software is running and convert this GMT time to the local time.
Please tell me how to do this?
Assuming your
timestamp
is either aDate
orNumber
:If your timestamp is given as a
String
, you first have to parse it. You'll find plenty of examples with custom format inSimpleDateFormat
, a simple example with built-in format:Assuming the server time in format
yyyy/MM/dd HH:mm:ss.SSS
this works:Have a look at Joda-Time. It has all the date related functions one needs
To get your local timezone :
Calendar.getInstance().getTimeZone().getDisplayName()
For the conversion:
Date TimeZone conversion in java?