aspose file tools*
The moose likes Java in General and the fly likes Java calendar issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java calendar issue" Watch "Java calendar issue" New topic
Author

Java calendar issue

Jeff Vybihal
Greenhorn

Joined: Sep 12, 2011
Posts: 2
I'm trying to figure out how to calculate the number of days between two specified dates but only on certain days of the week. The code below should work however, after I set the variable current to 7/1/2011 I then display the value of current and it doesn't reflect what day of the week it should really be.

For example, 7/1/2011 falls on a Friday or integer value 6. If you run the code shown below, what you see is the value 2 (Monday) being returned.

I am determining the integer values based on the Calendar API

Calendar.MONDAY
Calendar.FRIDAY




Any ideas?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

When you use "7" in that position it means "August", not July. You aren't passing a month number, you are passing one of the Calendar constants. In this case you are passing Calendar.AUGUST, whose value is 7. Change the program to pass Calendar.JULY and see what happens.
Jeff Vybihal
Greenhorn

Joined: Sep 12, 2011
Posts: 2
Thanks for the speedy reply. This greenhorn missed that key information!

Thanks again!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

It's an often made mistake, and I blame Sun for this. They chose to let weekdays start at 1 (Calendar.SUNDAY), which is OK. Yet they chose to let months, which naturally start at 1, start at 0 (Calendar.JANUARY). This makes no sense whatsoever. They should either have made both start at 0 (to be consistent) or both start at 1 (again, to be consistent, but also to be more friendly).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java calendar issue