Why is 1942/4/3 00:00:00 an illegal date in java.util.Calendar?
Posted
by Aleksi
on Stack Overflow
See other posts from Stack Overflow
or by Aleksi
Published on 2010-06-16T13:10:22Z
Indexed on
2010/06/16
13:22 UTC
Read the original article
Hit count: 191
Is there something special in the date 3rd of April 1942? For some reason the the hour of day 0 (12:00 am) is illegal for this specific date. The date is accepted when a lenient calendar is used but the hour of day is incremented to 1 (1:00 am).
Relevant code
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.clear();
calendar.setLenient(false);
calendar.set(1942, 3, 3, 0, 0, 0);
calendar.getTimeInMillis();
Exception
java.lang.IllegalArgumentException: HOUR_OF_DAY
at java.util.GregorianCalendar.computeTime(Unknown Source)
at java.util.Calendar.updateTime(Unknown Source)
at java.util.Calendar.getTimeInMillis(Unknown Source)
I'd really prefer is the dates were not lenient as I don't want to accept impossible dates.
© Stack Overflow or respective owner