-
August 2nd, 2012, 06:51 PM
#1
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?
-
August 2nd, 2012, 07:01 PM
#2
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";
-
August 6th, 2012, 04:54 PM
#3
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|