Year getting set 1970 when parse using SimpleDateFormat jdk1.4

563 views Asked by At
SimpleDateFormat formatObject = new SimpleDateFormat("yyyy-MM-dd");   
String attrValue="2015-09-24";   
Date date = ((SimpleDateFormat) formatObject).parse(attrValue);    
java.sql.Date parsedValue = new java.sql.Date(date.getTime());    

randomly some time it prints parsedValue 1970-09-24 sets year to 1970 instead of 2015, if parse again same it parse correctly to 2015-09-24 not getting reason why some time parse sets year to 1970. We are using jdk1.4

1

There are 1 answers

0
Chethan C On BEST ANSWER

Try DateFormat.setLenient(false); and watch out whether the issue is in java.util.Date or java.sql.Date.