This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem with simple date format class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with simple date format class" Watch "Problem with simple date format class" New topic
Author

Problem with simple date format class

Ram Korutla
Ranch Hand

Joined: Dec 24, 2007
Posts: 80
Hi,

I am using the below code snippet. When I am using 201230, the year being returned is 2020. If I input 301230, it gives 1930. I am expecting 1920 similarly for 201230 input also. Can some one please clarify, what I need to do to ensure I get 1920 instead of 2020? Also, the other issue, is how does java know whether it is a future date input or input of past date?

Sorry for this simple issue.



Thanks
Ram
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4377
    
    8

According to the SimpleDateFormat specification:
For parsing with the abbreviated year pattern ("y" or "yy"), SimpleDateFormat must interpret the abbreviated year relative to some century. It does this by adjusting dates to be within 80 years before and 20 years after the time the SimpleDateFormat instance is created.

So for "30" to parse as "2030", just wait about three weeks! More generally, if you want the year to always be parsed as this century, you might want to insert a "20".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with simple date format class