# Doubt : Calendar.WEEK_OF_YEAR

Sridhar Santhanakrishnan

Ranch Hand

Posts: 317

posted 7 years ago

I was just going through the Calendar API and the constant WEEK_OF_YEAR is defined as

I tried it out....

This was the output

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

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

WEEK_OF_YEAR: 1

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

posted 7 years ago

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 ]

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 ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions