This is one of many ways in which java.util.Calendar is counterintuitive. It does work, but not the way you're expecting. Look at the documentation[ for the DAY_OF_WEEK field: "This field takes values SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY." When your program prints 6, it's telling you that the day of week is FRIDAY. This constant value has nothing to do with the beginning of the week - it's just a constant that means FRIDAY. It does coincidentally happen to be the same as the day of the week if the first day of the week is SUNDAY (1) - but it doesn't change if the first day of the week is redefined.
Compare this to the API for WEEK_OF_MONTH and WEEK_OF_YEAR, which do say that they depend on the first day of the week. You can test to see if this works correctly for your purposes.
If you really need a number representing day of week with 1 meaning Monday and 7 meaning Sunday, you can get it with a tiny bit of math:
[ October 27, 2006: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
posted 12 years ago
Thanks for your reply. In the meantime I realized that the days are constants, that's why it will return 6 for FRIDAY, no matter what the first day of the week is set to.
I added the logic to shift the value returned if SUNDAY is the first day of the week.
a wee bit from the empire
how do I do my own kindle-like thing - without amazon