This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Print the first Friday of every month... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Print the first Friday of every month..." Watch "Print the first Friday of every month..." New topic
Author

Print the first Friday of every month...

Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
Dear Friends,
I have a problem. I want to use the java API and print the first Friday of every month for a given year. Can anyone help me out as to how to achieve the solution.
thanks in advance.
shekar.


Thanks,
Shekar
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Take a look at the java.util.Calendar and java.util.GregorianCalendar classes from the Java API. You will simply want to create a date object as the January 1 of the year in question, go to the first Friday (by testing what day of the week the first is, and then doing the necessary calculation to get to the first Friday), then go to the first of the next month and do the same, or once you have the first Friday of the year, simply iterate through the year 7 days at a time and see if the month changes form the previous value; if it does, it�s a new month and thus the first Friday of the month.
You can also look at example 376 - Comparing Dates and other related examples at JavaAlmanac.com.
Also take a look at the JavaWorld articles Calculating Java dates and Working in Java time : Learn the basics of calculating elapsed time in Java.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Can anyone help me out as to how to achieve the solution.
Yes, many of us can and are happy to do so. Work in very small steps, solving one very small part at a time. Show us what you're working on. (Post your code.) And explain what part you're having difficulty understanding.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Print the first Friday of every month...
 
Similar Threads
Create and print reports - best solution
First day of the first week of the month
Calendar problem
email format problems
Passed SCJD 400/400