这个问题在这里已经有了答案:
How to Parse Date in ISO format in Java? [duplicate]
(2 个回答)
5年前关闭。
将 UTC 日期时间解析为 EST 本地时间时出现以下异常。
异常(exception):
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并尝试了那里提出的解决方案,但没有奏效。
最佳答案
输入格式有误。您已将毫秒指定为格式 .SSS 的输入,然后是 Z 区。
但是,您还没有通过毫秒选项。以下格式有效
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
关于java - 无法将 UTC 日期时间解析为 EST 本地时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39403270/