I am working with timezones in a Java application using JodaTime. I encounter a problem when trying to build a DateTimeZone (JodaTime) object from the id of a java timezone. Joda throws a
java.lang.IllegalArgumentException: The datetime zone id 'SystemV/HST10' is not recognised
for the folowing list of timezones:
What are these timezones used for? Are they relevant to non-programmers? Should an application designed for general uses support these timezones?
Thanks.
As Jon Skeet already said, java.util.Date does not have a time zone. A Date object represents a number of milliseconds since January 1, 1970, 12:00 AM, UTC. It does not contain time zone information.
Time zone data is provided by the public IANA time zone database. The following table shows all the time zones supported by Joda-Time, using version 2018g of the database. It is also possible to update to a later version of the database.
Note that from Java SE 8 onwards, users are asked to migrate to java.time (JSR-310) - a core part of the JDK which replaces this project. Solution using java.time, the modern Date-Time API: If you want to get just date and time (and not the timezone information), you can use LocalDateTime.#now (ZoneId).
In Java 8 you'd use java.time.ZonedDateTime, which is the Java 8 equivalent of Joda Time's DateTime. @user3132194: And what benefit do you think that will have over new Date ()? It is just a template for copy-paste, based on your answer. You said that Date is always UTC-based. I need local time.
The SystemV time-zone IDs are old and deprecated. However, you can make Joda-Time understand them by re-compiling the joda-time jar file with the systemv time-zone data file included. See the commented out lines in the systemv data file. (ie. uncomment the lines and rebuild the jar file).
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