This question already has answers here:
How to Parse Date in ISO format in Java? [duplicate]
(2个答案)
3年前关闭。
将UTC日期时间解析为EST当地时间时遇到以下异常。
例外:
GenericUtils.java
在java.text.ParseException: Unparseable date "yyyy-MM-dd'T'HH:mm:ss.SSSZ" - SimpleDateFormat处的SO上找到了类似的内容,并尝试了在那里提出的解决方案,但没有用。
(2个答案)
3年前关闭。
将UTC日期时间解析为EST当地时间时遇到以下异常。
例外:
Stacktrace:] with root cause
java.text.ParseException: Unparseable date: "2016-09-09T03:00:29Z"
at java.text.DateFormat.parse(DateFormat.java:357)
at com.study.crud.util.GenericUtils.convertUTCDateToEST(GenericUtils.java:55)
GenericUtils.java
public static String convertUTCDateToEST(String utcDate) throws ParseException {
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
inFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date aDate = inFormat.parse(utcDate);
DateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd HH:MI:SS");
outFormat.setTimeZone(TimeZone.getTimeZone("EST"));
String estDate = outFormat.format(aDate);
return estDate;
}
在java.text.ParseException: Unparseable date "yyyy-MM-dd'T'HH:mm:ss.SSSZ" - SimpleDateFormat处的SO上找到了类似的内容,并尝试了在那里提出的解决方案,但没有用。
最佳答案
输入格式有误。您已指定毫秒作为格式.SSS的输入,然后是区域Z。
但是,您尚未通过毫厘第二个选项。以下格式适用
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");