• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

First Weekday Of Month

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to calculate the first weekday of the current month. I was going to attempt calculating using this type of approach, but this leaves the possibility of it still checking the first 3 days of the month. The only way in which i could combat this is by using a file as a flag mechanism as this program daily as opposed to persistently...

GregorianCalendar cal = new GregorianCalendar();
currday = cal.get(Calendar.DAY_OF_MONTH);
dow = cal.get(Calendar.DAY_OF_WEEK);
if (currday < 3){ //only check first 3 days of month
if (dow >= 2 && dow <= 6 ){ // = weekday (sat = 7, sun = 1)
bMonthend = true;
}else{
bMonthend = false;
}
}

Many thanks
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could force the GregorianCalendar to go to the first day of the current month:

You can find information about the methods available by using the Java API docs. In this case, you would probably start by navigating to the GregorianCalendar class. Then you would discover that much of GregorianCalendar's functionality is in its base class Calendar. This is where I found information about the set() method.

Keep Coding!

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic