File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calendar problem !!" Watch "Calendar problem !!" New topic
Author

Calendar problem !!

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 ,

Thanks,

Reagrdz,


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

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
    
    1

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