Ilya
Ilya

Reputation: 29693

Confusing time zones when parsing dates in Joda Time

TZ on my comp is GMT+5.

  final DateTime date1 = dtf.parseDateTime("1979-04-29");
  final DateTime date2 = dtf.parseDateTime("1979-05-12");
  final DateTime date3 = dtf.parseDateTime("1979-04-02");
  final DateTime date4 = dtf.parseDateTime("1979-04-15");
  System.err.println(date1.toString());
  System.err.println(date2.toString());
  System.err.println(date3.toString());
  System.err.println(date4.toString());

Output is

1979-04-29T00:00:00.000-05:00
1979-05-12T00:00:00.000-04:00
1979-04-02T00:00:00.000-05:00
1979-04-15T00:00:00.000-05:00  

-04? Why?

If add

DateTimeZone.setDefault(DateTimeZone.forID("Etc/GMT+5"));  

before, then output will be

1979-04-29T00:00:00.000-05:00
1979-05-12T00:00:00.000-05:00
1979-04-02T00:00:00.000-05:00
1979-04-15T00:00:00.000-05:00 

Upvotes: 4

Views: 239

Answers (1)

Brian Roach
Brian Roach

Reputation: 76898

That would be called "Daylight Saving Time" : http://timeanddate.com/time/dst/1979.html

At 02:00 on 1979-04-29 it changed to -04:00

Upvotes: 3

Related Questions