Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print the first Friday of every month...

 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic