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.
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"
.
I've even tried writing the string date directly into the parse method;
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.
一切都应该没问题。尝试删除区域设置,有时可能会导致奇怪的错误,具体取决于环境。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.