给定一个输入日期字符串,我想解析输入日期字符串。这个输入日期格式最后我想更改为其他日期格式。但目前我得到异常,而解析输入字符串本身。
String startDateString = " Jun 28, 2015T12:00:00 AM";
DateFormat df = new SimpleDateFormat("MMM dd, yyyy'T'hh:mm:ss a");
java.util.Date startDate;
try {
startDate = df.parse(startDateString);
String newDateString = df.format(startDate);
System.out.println(newDateString);
} catch (ParseException e) {
e.printStackTrace();
}
}
Getting the following exception,
java.text.ParseException: Unparseable date: " Jun 28, 2015T12:00:00 AM"
at java.text.DateFormat.parse(DateFormat.java:357)
at promo.json.parser.handler.Test.main(Test.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
行距
您的输入值" Jun 28, 2015T12:00:00 AM"
与解析格式不匹配,因为String::trim()
之前的前导空格字符。
尝试将字符串编辑为:
String startDateString = "Jun 28, 2015T12:00:00 AM";
或调用CC_4:
startDateString.trim();