This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Calendar problem !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calendar problem !!" Watch "Calendar problem !!" New topic

Calendar problem !!

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

HI ranchers,

I am trying to set date as ' 30 April 2008' i.e 4/30/08 , but i am getting a date which is a month ahead ??

my code :

when i run this , i am expecting to get ' April 30, 2008' , but output is : 'May 30, 2008 '

what`s wrong here ? Any solution ,



[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Months are indexed from 0, so April is actually 3. Try using the Calendar constants to avoid this sort of error, e.g.:

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

ohhh , thanks Paul, I ll burn that in my mind !!!
I agree. Here's the link:
subject: Calendar problem !!
It's not a secret anymore!