• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GregorianCalendar

 
tom smith
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URLyBird:

I am using a StringTokenizer to read the room date from the file.

Then I am setting up a GregorianCalendar (since many Date methods are deprecated) for today and the room date.



However, for the 12th month, when I test the results I get the following month, which rolls me over to the next year.

For all other months the date values are correct.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"tom abcdefghi", a little formality: Please change your displayed name to conform with our JavaRanch Naming Policy. We prefer you to use your real name in the form <first name><space><family name>. We usually lock out the accounts with non-conforming displayed names.

Thanks
-Barry

(NR)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your months are based on Jan = 0, as GregorianCalendar/Calendar requires?
 
tom smith
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no....

it looks as though year and date are 1 based and month is 0 based?

odd.

--

i did change the name.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's it - Calendar and subclasses use 0 for basing the month. Yes, it's counterintuitive. But that's the way Sun did it.
 
Eiji Seki
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weird but not 100% ilogical.
Days and years are numeric, but months are not.
Months are an ordered list of names, so we have Jan, Feb and so on, but we end up using their order as well. Since indexes and everything in Java is zero based, so should be the indexes of the months.
 
tom smith
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eiji - true.

and logical, in it's own way!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic