how do you account for two possible date formats one with milliseconds and one without when parsing date using simpledateformat? [duplicate]

浪尽此生 提交于 2021-01-29 18:03:36

问题


There can be two different date time formats as shown below. The second variant has milliseconds time.

2020-09-07T16:15:42Z
2020-09-09T11:41:58.5152Z

Currently i am using this way to parse the date. Is there a way to specify a single format to account for both of these two cases?

def dateutc = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'"))

 dateutc.setTimeZone(TimeZone.getTimeZone("UTC"))

 time = dateutc.parse(point.time.toString()).getTime()

Thanks for the help!

Please note i am using java 7.

来源:https://stackoverflow.com/questions/63857192/how-do-you-account-for-two-possible-date-formats-one-with-milliseconds-and-one-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!