[英]SimpleDateFormat.parse - ParseException
I'm trying to parse a (String) date into Date object, but no matter what pattern I use for SimpleDateFormat
, I simply can't make it work, I always end up with getting a ParseException. 我试图将一个(String)日期解析为Date对象,但是无论我为
SimpleDateFormat
使用哪种模式,我都无法使其正常工作,最终我总是得到ParseException。
Code: 码:
SimpleDateFormat sdf = new SimpleDateFormat("E MMM, d, h:mm a", Locale.US);
String strDate = "Tue Sep, 18, 3:30 AM";
Date newDate = null;
newDate = sdf.parse(strDate);
The above code gives me a Exception: java.text.ParseException: Unparseable date: "Tue Sep, 18, 3:30 AM"
. 上面的代码给了我一个
Exception: java.text.ParseException: Unparseable date: "Tue Sep, 18, 3:30 AM"
。
I've even tried writing the string date directly into the parse method; 我什至尝试将字符串日期直接写到parse方法中。
newDate = sdf.parse("Tue Sep, 18, 3:30 AM");
But that doesn't make any difference. 但这没有任何区别。
I'm cleary doing something wrong, but I just don't see where. 我很明显在做错事,但是我看不到哪里。 I've read http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html over and over, and tried different
SimpleDateFormat#pattern
but haven't manage to solve it. 我已经一遍又一遍地阅读了http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html ,并尝试了不同的
SimpleDateFormat#pattern
但没有设法解决。
一切都应该没问题。尝试删除区域设置,有时可能会导致奇怪的错误,具体取决于环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.