Mario Skrlec wrote:I understand that Calendar.SUNDAY has value 1, Calendar.MONDAY has value 2 but why does the getFirstDayOfWeek() returns 2 as if the first day of week is Calendar.MONDAY?
Because that's probably the case. There are two popular settings for the first day of the week - Sunday or Monday. Apparently Calendar uses Monday. Fortunately, you can change that if you want to, with Calendar.setFirstDayOfWeek.
In this month, starting day is Thuesday, thus the value of weekday is 3. So how come weekdayNames doesnt start with 0 where 0 would be sunday? Instead, it starts with 3, wich in monday, then adds 1 everytime it goes through the loop beacuse of add(). When it comes to 7, next one is 1 and ends with 2 wich is the same as firstDayOfWeek.
You're mistaken. weekdayNames uses Calendar.SUNDAY through Calendar.SATURDAY for its indexes. It doesn't start with 3 at all (and 3 is Tuesday, not Monday). It starts at 0 like any other array, although that value is undefined and meaningless. Like I said, use Calendar.SUNDAY through Calendar.SATURDAY to access its values. Fortunately,
d.get(Calendar.DAY_OF_WEEK) returns one of these values.
Another thing,
sunday has value 2012 which is, geniously deducted, this year. On the other hand, Calendar.MONDAY is 2. All of the code is from Core Java I.
You're calling the method incorrectly. The argument should be one of the calendar fields. You're using Calendar.SUNDAY, but that's just an int. It has the same value as Calendar.YEAR, which is 1. That means that
inst.get(Calendar.SUNDAY) is the same as
inst.get(Calendar.YEAR) which returns the year - 2012.