Joda时间将异常抛出为:
java.lang.IllegalArgumentException:无效格式:“ 2020年4月23日 UTC的10:35:06 AM UTC格式不正确 org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:873) 在org.joda.time.DateTime.parse(DateTime.java:144)处 org.joda.time.DateTime.parse(DateTime.java:133)
导致此异常的代码行是:
public static DateTimeFormatter LicenseFormat = DateTimeFormat.forPattern("dd-MMM-yyyy hh:mm:ss a z").withZone(DateTimeZone.UTC).withLocale(Locale.ENGLISH);
DateTime webDate = DateTime.parse(DateTime.now().toString(LicenseFormat));
我无法找到问题所在,日期“ UTC 2020年4月23日上午10:35:06”采用“ dd-MMM-yyyy hh:mm:ss az”的正确格式,为什么会这样引发异常。
答案 0 :(得分:1)
哦,非常小的问题,我应该将第二个参数传递给类型为parse()
的方法DateTimeFormatter
。
为:
DateTime webDate = DateTime.parse(DateTime.now().toString(LicenseFormat), LicenseFormat);