ParseException: Unparseable date:

孤者浪人 提交于 2019-12-20 06:09:17

问题


I have timestamp string like "2015-07-13T10:44:58Z" whe I try convert this in date object it always generates the exception

Caused by: java.text.ParseException: Unparseable date: "2015-07-13T10:44:58Z"

Code which I am using for parsing is like that

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    Date subscriptionDate = format.parse("2015-07-13T10:44:58Z");

I don't know what I am doing wrong.


回答1:


The patterm SSS stands for Millisecond - which means that your input needs to have 3 decimal places after the second - see here.

Your input, however, has no millisecond information. You have to remove the SSS or add the digits manually (.000).




回答2:


Your input is inconsistent with your pattern: pattern has millisecond information (.SSS) while input does not (it ends with seconds followed by 'Z'). So you should either provide milliseconds in your input or remove .SSS from date pattern



来源:https://stackoverflow.com/questions/31381554/parseexception-unparseable-date

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