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.
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.
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:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With