Question

I'd like to increment minutes in some dates but when the result must be at 2am, it gives 3am. This issue occurs only at 2am! Let's take a look at the code here :

SimpleDateFormat spf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm", java.util.Locale.FRANCE);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.HOUR_OF_DAY, 2);
out.print(spf.format(cal.getTime()));
Was it helpful?

Solution

This is a Daylight Savings Time issue: on some time zones there is no 2AM for that date; and there are two 2AM times with one hour difference.

As an example, here in Greece, on March 30th there will be no 3AM ; the clock will go from 02:59:59 to 04:00:00, and on October 26th the clock will go from 03:59:59 back to 03:00:00.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top