I came across a comment in some java code that states that getTime()
needs to be called to update the Calendar
object. Is this true? I cannot find anything that says that this is necessary.
Here's the code:
Calendar cal = new GregorianCalendar();
cal.setFirstDayOfWeek(Calendar.SUNDAY);
cal.set(2009, 9 - 1, 10, 2, 30);
// Get Time needs to be called to update the Calendar object
cal.getTime();
Best Answer
cal.getTime()
does indeed need to be called to re-calculate its internals. It is very strange behavior for the API but the Calendar javadocs state this explicitly:...
The behavior is unexpected and does not always occur but the following unit tests should exemplify this behavior and always occur.