简体   繁体   English

在Joda Time中解析日期时混淆时区

[英]Confusing time zones when parsing dates in Joda Time

TZ on my comp is GMT+5. 我的比赛上的TZ是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? -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 

That would be called "Daylight Saving Time" : http://timeanddate.com/time/dst/1979.html 这将被称为“夏令时”: http//timeanddate.com/time/dst/1979.html

At 02:00 on 1979-04-29 it changed to -04:00 1979-04-29 02:00 ,它改为-04:00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM