无法将 UTC 日期时间解析为 EST 本地时间
Not able to parse UTC date time to EST local time
将 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 上找到了一些类似的东西,并尝试了那里提出的解决方案,但没有奏效。
这是因为您输入的 millisecond
部分时间不存在:
"2016-09-09T03:00:29Z"
^ unmatched place
您可以通过添加缺失的部分来修改输入(2016-09-09T03:00:29.000Z
) 或相应地更改您的格式模式(yyyy-MM-dd'T'HH:mm:ss'Z'
)。
此外,您的输出格式(时间的分钟部分)有一个拼写错误:
"yyyy-MM-dd HH:MI:SS"
应该换成yyyy-MM-dd HH:mm:ss
。
输入格式有误。您已将毫秒指定为格式 .SSS 的输入,然后是区域 Z。
但是您没有通过毫秒选项。以下格式有效
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
将 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 上找到了一些类似的东西,并尝试了那里提出的解决方案,但没有奏效。
这是因为您输入的 millisecond
部分时间不存在:
"2016-09-09T03:00:29Z"
^ unmatched place
您可以通过添加缺失的部分来修改输入(2016-09-09T03:00:29.000Z
) 或相应地更改您的格式模式(yyyy-MM-dd'T'HH:mm:ss'Z'
)。
此外,您的输出格式(时间的分钟部分)有一个拼写错误:
"yyyy-MM-dd HH:MI:SS"
应该换成yyyy-MM-dd HH:mm:ss
。
输入格式有误。您已将毫秒指定为格式 .SSS 的输入,然后是区域 Z。
但是您没有通过毫秒选项。以下格式有效
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");