new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2009-03-08 02:38:13")
returns: Sun Mar 08 03:38:13 PDT 2009. Actually, if I change the date&time to "2009-03-08 03:38:13", it returns the same thing!
Here is the code:
public static void main(String[] args) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
//dateFormat.setLenient(false);
try {
System.out.println("date is "+dateFormat.parse("2009-03-08 03:38:13"));
System.out.println("date is "+dateFormat.parse("2009-03-08 02:38:13"));
} catch (ParseException e) { e.printStackTrace(); }
}
If dateFormat.setLenient(false) is uncommented out, it throws a ParseException.
What a weird problem. Does anybody have any ideas?
Re: new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2009-03-08 02:38:13")
Sorry, DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
Re: new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2009-03-08 02:38:13")
It works perfectly on my system. I get the correct date and times and lenient does not throw an exception.
Are you sure this is the code you are running?
What OS are you running on and what version of Java are you using?