Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java doesn't have information about all IANA time zones

Tags:

People also ask

How does Java handle time zones?

If you cannot change the OS or the JVM timezone, you can still convert a Java Date/Time or Timestamp to a specific time zone using the following two JDBC methods: PreparedStatement#setTimestamp(int parameterIndex, Timestamp x, Calendar cal) – to convert the timestamp that goes to the database.

Where does Java get TimeZone?

TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time.

What are the Java TimeZone IDs?

ECT - Europe/Paris. IET - America/Indiana/Indianapolis. IST - Asia/Kolkata. JST - Asia/Tokyo.


I'm trying to map the values that come from the Front-End to ZoneId class like this:

Optional.ofNullable(timeZone).map(ZoneId::of).orElse(null)

For most time zones it works fine, however, for some values Java throws exception:

java.time.zone.ZoneRulesException: Unknown time-zone ID: America/Punta_Arenas

However, it is a valid time-zone according to IANA: https://www.iana.org/time-zones

Zone America/Punta_Arenas -4:43:40 - LMT 1890

I was thinking about using offset for such time-zones (just to hardcode values), but I guess there should be more convenient way to solve the issue. Is there a way Java can handle that?

Other timezones that are not supported:

  • America/Punta_Arenas
  • Asia/Atyrau
  • Asia/Famagusta
  • Asia/Yangon
  • EST
  • Europe/Saratov
  • HST
  • MST
  • ROC

My Java version: "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)