my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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: 2902

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: 2902

ohhh , thanks Paul, I ll burn that in my mind !!!
It is sorta covered in the JavaRanch Style Guide.
subject: Calendar problem !!
Similar Threads
Expressiveness using implicit conversions
first date and last date of month into java.sql.timestamp
Can i get month in words( eg:January) using Date,Calendar or GregorianCalendar API
casting date