Beware the ides of March

Posted on June 9, 2008 09:10 by brian

Well, OK, perhaps not...

However, beware the Java Calendar object.  While DATE and YEAR are 1 based, MONTH is zero based!  If you're just doing a comparison with a known month, no problem.  However, if you're expecting a useful int value for construction a date string (like say for passing to a SQL server as part of a query), you may meet with a most unpleasant surprise.

It appears that MONTH was just designed with direct comparisons in mind.  However, there is no other decent way to get a MONTH int out of the object, and building a big case to figure it out is just silly.  Sure wish they would have just made it 1 based and avoided this goofiness... 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

August 28. 2008 03:26