简体   繁体   中英

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. 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. (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?. 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. 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.

If you had used a time zone or such you would see the effects of DST, but instead you are getting the correct answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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