• Post Reply Bookmark Topic Watch Topic
  • New Topic

First Weekday Of Month  RSS feed

 
Mark Mero
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!