简体   繁体   中英

Calendar java does not work properly

import java.util.Calendar;

...

Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(1443351600000L));// set to 2015-9-27
calendar.add(Calendar.HOUR_OF_DAY, 23); // add 23 hours

I don't know why calendar is updated from 2015-09-27 00:00:00 to 2015-09-28 00:00:00 . I expect 2015-09-27 23:00:00 .

Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(1443351600000L));// set to 2015-9-28
calendar.add(Calendar.HOUR_OF_DAY, 23); // add 23 hours

And this one works fine. The result is 2015-09-28 23:00:00 .

There's only 23 hours in the day if Daylight Saving Time starts on 2015-9-27 .

Google search says the following starts Daylight Saving Time on Sep 27, 2015:

If you're in one of these places, there's your 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