wood burning stoves 2.0
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with simple date format class" Watch "Problem with simple date format class" New topic

Problem with simple date format class

Ram Korutla
Ranch Hand

Joined: Dec 24, 2007
Posts: 80

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.

Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

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
It's not a secret anymore!