Question

Possible Duplicate:
Java Calendar Setting Incorrectly

i have this code:

GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(Locale.FRENCH);
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.set(Integer.parseInt(Year), Integer.parseInt(Month), Integer.parseInt(Day));
int weekday= cal.get(Calendar.DAY_OF_WEEK);

If i pass for example 2012-04-02 (a Monday) weekday = 4. And if i pass 2012-04-06(a Friday) weekday = 1. So gregorianCalendar thinks friday is the first day altough I said Monday is the first day? How to fix this?

Thanks in advance!

Was it helpful?

Solution

4 in GregorianCalendar is May, not April, so the answer is correct. When you insert 4 as Calendar.MONTH, the date is actually 02/05/2012, which is a Wednesday.

Remember that months are 0-based.

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