Aravind Yarram
Aravind Yarram

Reputation: 80186

What is the joda-time equivalent of few JDK TimeZone functions

what is the joda-time equivalent of below methods in JDK.

  1. TimeZone.getOffset()
  2. TimeZone.getRawOffset()
  3. TimeZone.inDaylightTime()
  4. TimeZone.useDaylightTime()
  5. TimeZone.getDSTSavings()

My main idea is to store the below in database as suggested by most of the SO posts

  1. time in UTC = joda Instant
  2. time zone offset = which is the equivalent in joda?
  3. dst offset = which is the equivalent in joda?

Also should i store the RawOffset or the DST adjusted offset?

Upvotes: 3

Views: 1120

Answers (1)

OrangeDog
OrangeDog

Reputation: 38777

  1. DateTimeZone.getOffset()
  2. DateTimeZone.getStandardOffset()
  3. ! DateTimeZone.isStandardOffset()
  4. ! DateTimeZone.isFixed()
  5. Not sure.

If you just save the UTC instant and the timezone id (i.e. America/New York and Europe/London, not EST and GMT) then you don't need to worry about storing raw offsets. Especially as offsets change with annoying frequency. Let Joda and the tz database do all the work for you. So store:

  1. ReadableInstant.getMillis()
  2. DateTimeZone.getId()

With Java 8, just use ZonedDateTime persisted via DateTimeFormatter.ISO_ZONED_DATE_TIME.

Upvotes: 4

Related Questions