简体   繁体   English

Java日期差异,Joda库和DST

[英]Java date difference, Joda libraries and DST

I have to calculate the difference between two dates which represent the departure and the arrival of a vehicle (how many hours it has traveled). 我必须计算两个日期之间的差,这两个日期分别代表车辆的出发和到达时间(行驶了多少小时)。 I'm currently using the Joda library. 我目前正在使用Joda库。 If I use the Hours class, 如果我使用小时课程,

DateTime begin = new DateTime("2012-03-25T00:00+00:00");
DateTime end = new DateTime("2012-03-26T00:00+00:00");
Hours h = Hours.hoursBetween(begin, end);

I get 24 hours as result. 结果我有24小时。 (h.getHours()). (h.getHours())。

I can get the number of hours passed between the two dates, but what can I do when in the interval considered the DST occurs?. 我可以获得两个日期之间经过的小时数,但是如果在间隔中认为DST发生了,我该怎么办? In fact since the day chosen (25th of march 2012) is the day when the DST occurs (in the Europe/London zone) I should get 23 hours as result. 实际上,由于所选的日期(2012年3月25日)是DST发生的日期(在欧洲/伦敦地区),因此我应该得到23个小时。 Is there any class/method that can handle this particular events? 是否有任何可以处理此特定事件的类/方法?

When you give a date with the +00:00 at the end you are specifying the UTC offset, so those are exact times and unaffected by DST. 当您在日期末尾提供+00:00时,您将指定UTC偏移量,因此这些时间是准确的时间,不受DST的影响。

If you had used a time zone or such you would see the effects of DST, but instead you are getting the correct answer 如果您使用了时区或类似的时区,您会看到DST的效果,但是您会得到正确的答案

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

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