• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Calendar class  RSS feed

 
Ansar Shah
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!