夏令时 plusHours 和 plusDays 之间的 JodaTime 差异

ben*_*enw 3 java jodatime dst

根据 JodaTime Javadoc,在向日期添加时间时,plusHours 和 plusDays 都处理 DST 调整。但是,从我的测试来看,添加几天的小时数与添加 1 天的时间会产生不同的结果。有人可以向我解释为什么下面的代码会给出下面的输出吗?

代码:

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date = format.parse("2014-11-01T02:00:00.000-0700");

System.out.println("origDate:  " + date);
System.out.println("plusDays:  " + new DateTime(date).plusDays(1).toDate());
System.out.println("plusHours: " + new DateTime(date).plusHours(24).toDate());
Run Code Online (Sandbox Code Playgroud)

输出:

origDate:  Sat Nov 01 02:00:00 PDT 2014
plusDays:  Sun Nov 02 02:00:00 PST 2014
plusHours: Sun Nov 02 01:00:00 PST 2014
Run Code Online (Sandbox Code Playgroud)

Mat*_*int 5

Not all local days have 24 hours. Assuming you are working in the US Pacific time zone, there are 25 hours on that particular day, due to the fall-back daylight saving time transition.

Calling plusHours(24) adds an exact duration of 24 hours elapsed time.

调用会plusDays(1)增加日历日,即使这一天不是 24 小时。