This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using Calendar class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Using Calendar class" Watch "Using Calendar class" New topic
Author

Using Calendar class

Ansar Shah
Greenhorn

Joined: May 02, 2007
Posts: 29
Hello everyone,

Can any body elaborate, how to get maximum number of weeks in a month given Calendar instance? For example in December 2007, if the first day of week is set to Calendar.SATURDAY, then total weeks should be 6. And it should be 5 in case the first day of week is set to Calendar.MONDAY.

The getMaximum(Calendar.WEEK_OF_MONTH) always returns 6;
and getMinimum(Calendar.WEEK_OF_MONTH) always returns 0.

Please help.
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
You don't want the getMaximum method, which will allways return 6.
Instead you want the getActualMaximum method, which works based on the given calendar.
Furthermore, the value will depend on the minimalDaysInFirstWeek, which I think by default is 4.

This said, both for saturdag as monday as start days of the week you will get 5 as result (with default minimalDaysInFirstWeek).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Calendar class
 
Similar Threads
Using Calendar class
Calendar : getting week of month
Calendar (WEEK_OF_MONTH) ????
setFirstDayOfWeek in Calendar
daysOfWeek function implementation