1
我试图用joda DateTime创建一个固定的日期时间,基于代码执行时间(当前系统时间)产生出人意料的不同结果。 下面是代码DateTime API根据代码执行时间产生不同的结果
DateTimeZone.setDefault(DateTimeZone.forID("Europe/Brussels"));
DateTime t1 = new DateTime().withDate(2012, OCTOBER, 28).withTime(2, 0, 0, 50);
//Note that 2012, OCTOBER, 28, 02:00:00 is a DST swtich time in Belgium
的代码产生两种不同的结果(时区偏移的变化)
//Please note that the local time zone is CET.
00:00:00:00 > execution time < 03:00:00 -> 2012-10-28T02:00:00.050+02:00
03:00:00:00 >= execution time =< 24:00:00 -> 2012-10-28T02:00:00.050+01:00
在另一方面,使用构造产生相同的结果
DateTimeZone.setDefault(DateTimeZone.forID("Europe/Brussels"));
DateTime dateTime = new DateTime(2012, OCTOBER, 28, 2, 0, 0, 50); //gives 2012-10-28T02:00:00.050+02:00
我有一个印象,应该使用构造函数而不是withDate/Time方法。但我有点困惑,为什么DateTime无法处理这个问题?