I just encountered a strange behaviour with the GregorianCalendar class, and I was wondering if I really was doing something bad.
This only appends when the initiali
It is getting the actual maximums of the current date/time. May has 31 days which is 3 more than 28 February and it will thus shift to 3 March.
You need to call Calendar#clear() after obtaining/creating it:
GregorianCalendar cal = new GregorianCalendar();
cal.clear();
// ...
This results in:
Sun Feb 28 23:59:59 GMT-04:00 2010
(which is correct as per my timezone)
As said in one of the answers, the java.util.Calendar and Date are epic failures. Consider JodaTime when doing intensive date/time operations.