Basic Java Calendar usage (gey first day of month)
Posted: Wed Jan 17, 2007 2:04 pm
I must be going insane. I haven't got a clue why this doesn't work 
I want to determine what day of the week it was at the 1st of this month (i.e. Monday 1st January)
Does that look right? So why is the first day of the week being returned as 5? I don't get it; 5 is a Thursday.
The clock and everything on my computer is correct so I must have completely misunderstood how to use the date stuff.
I want to determine what day of the week it was at the 1st of this month (i.e. Monday 1st January)
Code: Select all
//Get the time right now
Calendar calendar = Calendar.getInstance();
//Set it to the first day of whatever month it is now
calendar.set(Calendar.DAY_OF_MONTH, 1);
//Now get the day of the week
int firstDayOfMonthAsDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
The clock and everything on my computer is correct so I must have completely misunderstood how to use the date stuff.