Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SystemV timezones and JodaTime

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:

  • SystemV/HST10
  • SystemV/YST9
  • SystemV/YST9YDT
  • SystemV/PST8
  • SystemV/PST8PDT
  • SystemV/MST7
  • SystemV/MST7MDT
  • SystemV/CST6
  • SystemV/CST6CDT
  • SystemV/EST5
  • SystemV/EST5EDT
  • SystemV/AST4
  • SystemV/AST4ADT

What are these timezones used for? Are they relevant to non-programmers? Should an application designed for general uses support these timezones?

Thanks.

like image 859
sebi Avatar asked May 21 '12 11:05

sebi


People also ask

What is the time zone of a date in Java?

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.

Where does Joda-Time get its time zone data?

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.

How to get date and time in Java SE 8?

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).

What is the Java 8 equivalent of Joda Time?

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.


1 Answers

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).

like image 165
JodaStephen Avatar answered Oct 22 '22 17:10

JodaStephen