File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Doubt : Calendar.WEEK_OF_YEAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt : Calendar.WEEK_OF_YEAR" Watch "Doubt : Calendar.WEEK_OF_YEAR" New topic

Doubt : Calendar.WEEK_OF_YEAR

Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
I was just going through the Calendar API and the constant WEEK_OF_YEAR is defined as
Field number for get and set indicating the week number within the current year. The first week of the year, as defined by getFirstDayOfWeek() and getMinimalDaysInFirstWeek(), has value 1. Subclasses define the value of WEEK_OF_YEAR for days before the first week of the year.

I tried it out....

This was the output


Can someone please throw more light on this? I expected 52(or 53).
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

Well this week can be regarded as week 1. I wrote a Visual Basic program just yesterday for my work, and it turned out that it sees this week as week 53 and next week as week 2 - week 1 is completely missing.

I've writte a similar program as yours to test it:

The output is 2, 2, 4 and 1, and then it makes sense.

Monday is the first day of the week. Because of that, Thursday, Friday, Saturday and Sunday are all in this week, and are all in January. So the minimal days in the first week (4) has exactly been matched, and therefore this is week 1.
[ December 30, 2008: Message edited by: Rob Prime ]

How To Ask Questions How To Answer Questions
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
makes sense. kind of.
I agree. Here's the link:
subject: Doubt : Calendar.WEEK_OF_YEAR
It's not a secret anymore!