无法将UTC日期时间解析为EST当地时间

编程入门 行业动态 更新时间:2024-10-28 01:12:17
本文介绍了无法将UTC日期时间解析为EST当地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在将UTC日期时间解析为EST当地时间时遇到以下异常.

Getting following exception while parsing UTC date time to EST local time.

例外:

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:无法解析的日期"yyyy-MM-dd'T'HH:mm:ss.SSSZ"-SimpleDateFormat 并尝试了在那里提出的解决方案,但是没有用.

Found some similar stuff on SO here java.text.ParseException: Unparseable date "yyyy-MM-dd'T'HH:mm:ss.SSSZ" - SimpleDateFormat and tried solutions proposed there but did not work.

推荐答案

输入格式有误.您已将毫秒指定为格式.SSS的输入,然后是区域Z.

There is a error in the input format. You have specified milli seconds as an input to your format .SSS and then the zone Z.

但是,您还没有通过毫秒选项.以下格式有效

You have however not passed the milli second option. The following format works

SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

更多推荐

无法将UTC日期时间解析为EST当地时间

本文发布于:2023-10-17 13:26:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1501059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:当地时间   日期   时间   UTC   EST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!