Get timezone of area with country code in Java

Manvi picture Manvi · May 24, 2018 · Viewed 16.1k times · Source

I have to pass a message (jms) with timezone info like (America/Los_Angeles) but I have only country name and code. If it possible get timezone info with Java code. Somewhere I read this:

System.out.println(TimeZone.getTimeZone("US"));

But its giving output as

sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

I am expecting List of "America/Los_Angeles", ...

Answer

arnt picture arnt · May 29, 2019

The builtin Java classes don't offer this, but ICU's TimeZone class does, and TimeZone.getAvailableIDs("US") provides the correct answer.