File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Number of weeks in a month Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Number of weeks in a month" Watch "Number of weeks in a month" New topic
Author

Number of weeks in a month

Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
Good Day,

Is there a class in Java that could compute for the number of weeks in a specific month?

Paul
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Calendar.getActualMaximum(Calendar.WEEK_OF_MONTH).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

And if you don't like the assumptions (about what constitutes a week) built into the Calendar class, you would still use the Calendar class to do the calculations based on your actual requirements.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You can tweak the week-definition, with two methods: setFirstDayOfWeek and setMinimalDaysInFirstWeek.
Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
Thanks guys....
 
GeeCON Prague 2014
 
subject: Number of weeks in a month