Unusual response when adding a minute to a calendar object

时间:2016-07-11 21:22:00

标签: java time

I wrote a function that creates a Calendar instance like this:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd HH:mm");
Calendar calendar = new GregorianCalendar(startYear, 0, 1, 0, 0);

I print the date in each row to the screen, and then add one minute:

calendar.add(Calendar.MINUTE, 1);

For all the years before 1999 it works fine, but when I try 1999 and it gets to 03/09/2016 01:59, adding a minute causes it jump backwards to 03/09/2016 01:00.

When I run the same script for 2016 it stops on 30/10/2016 1:59, and when adding a minute it results in 30/10/2016 1:00.

What could be going on here?

0 个答案:

没有答案