• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Print the first Friday of every month...

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic