| 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: 3786
|
|
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".
|
 |
 |
|
|
subject: Problem with simple date format class
|
|
|