Java: Calculating time zone difference

Adam Matan picture Adam Matan · Apr 3, 2013 · Viewed 27.5k times · Source

How do I get the time difference from GMT for a specific date and time zone in Java?

Determining whether a specific time zone is in DST is quite straight-forward:

boolean isIsraelInDST = TimeZone.getTimeZone("Israel").inDaylightTime(new Date());

How do I get the actual time difference?

Answer

Evgeniy Dorofeev picture Evgeniy Dorofeev · Apr 3, 2013

Use TimeZone.getRawOffset(): Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone. Because this value is not affected by daylight saving time, it is called raw offset.

If you want the offset including DST then you use TimeZone.getOffset(long date). You should provide the concrete date to the method, eg now - System.currentTimeMillis()