Invalid date is populated when we use yyyy-MM-dd'T'HH:mm:ssXXX format in java [duplicate]

a 夏天 提交于 2021-02-04 08:41:09

问题


When we convert the date from yyyy-MM-dd'T'HH:mm:ssXXX to YYMMDD date is invalid.

Say.. If the date is 2019-02-27T12:52:58.249Z then the converted date is generated as "190258"


回答1:


The issue is because of 'D' in the input format.

D represents Day of the year - so when we give 2019-02-27 it adds the 31 days in Jan and 27 days in Feb so the day is counted as '58'.

After changing the format to 'd' it works fine.

Similarly, 'Y' represents week of the year - so we have replaced that to 'y' which represents year



来源:https://stackoverflow.com/questions/54918883/invalid-date-is-populated-when-we-use-yyyy-mm-ddthhmmssxxx-format-in-java

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