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

Help required for Calendar

Mandar Puranik
Ranch Hand

Joined: Jan 08, 2003
Posts: 35
Hi Friends,
Please can you help me ?
I need to do following.
I have to find out all(or 1st and 3rd) Saturdays and Sundays in
an year.
For that, I want to set the calendar date to 1st Jan of that year,
so that I can start from there and then find the required Saturdays and
How should I proceed ?

To Bug is Human,<br />To Debug Divine... :-))
David Peterson
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
Personally, I would use a "brute force and ignorance" approach... just iterate through each day of the year, and check whether it's a Saturday or Sunday.

Obviously if you want 1st/3rd weekends you're going to need a bit more logic in there. You may also need to decide whether if the first day of a month begins on a Sunday that counts as the "1st Sunday" of the month, or whether you are talking about Sat+Sun together.
Hope this helps get you started.
David Peterson
Sonny Pondrom
Ranch Hand

Joined: Jun 05, 2001
Posts: 128
You might want to make a calender object that has a method that would return a list of dates for a given year and the target day of the week needed.
The day offset would be a number from the first day of the year to the target day of the week.
Then you could make a list of Lunar calender days by accumulating in 14 day increments until the total is more than 366.
Then you could make a method that changed a lunar date to a Gregorian date.
And finally convert the Lunar list to make your output list.
Hope this helps.
Mandar Puranik
Ranch Hand

Joined: Jan 08, 2003
Posts: 35
Hi David and Sonny,
Thanks for you advice. It helped me a lot.
I used the advice you two gave.
I just set the day of the calendar to the 1st Jan of that year.
Then iterated to get all the sundays and saturdays.
Its working perfectly correct.
Thanks and Warm Regards
I agree. Here's the link:
subject: Help required for Calendar
It's not a secret anymore!