My problem seems to be extremely simple. I create a calendar graphical user interface from a GregorianCalendar object and use it to calculate the correct number of days in different months and another date corresponding to work days.
But weekdays are consistent on one day off. The calendar claims July 1, 2013 to be “2,” which in my part of the world means Tuesday. It was supposed to be "1" on Monday. "Easily!" I think, and put in a line: c.setFirstDayOfWeek (Calendar.MONDAY); But the reaction is not given.
So, I'm looking for stackoverflow for an answer, but everyone with my problem seems to have forgotten that January is 0, not 1. I haven't. So now I'm stuck.
As a simplified code, I made a very short piece of code with the corresponding output:
GregorianCalendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.set(Calendar.MONTH, 6);
c.set(Calendar.DAY_OF_MONTH, 1);
c.set(Calendar.YEAR, 2013);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYYY");
System.out.println(sdf.format(c.getTime()));
System.out.println(c.get(Calendar.DAY_OF_WEEK));
and output:
07/01/2013
2
I refuse to insert "-1" in my code to incorrectly fix the symptoms of what is obviously an error. Help is appreciated.
source
share