当我们在Java中使用yyyy-MM-dd'T'HH:mm:ssXXX格式时,将填充无效的日期 [英] Invalid date is populated when we use yyyy-MM-dd'T'HH:mm:ssXXX format in java
问题描述
当我们将日期从yyyy-MM-dd'T'HH:mm:ssXXX转换为YYMMDD时,日期无效.
When we convert the date from yyyy-MM-dd'T'HH:mm:ssXXX to YYMMDD date is invalid.
说..如果日期是2019-02-27T12:52:58.249Z那么转换后的日期将生成为"190258"
Say.. If the date is 2019-02-27T12:52:58.249Z then the converted date is generated as "190258"
推荐答案
问题是由于输入格式中的'D'引起的.
The issue is because of 'D' in the input format.
D代表一年中的某天-因此,当我们给出2019-02-27时,它将1月的31天和2月的27天相加,因此该天被视为'58'.
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'.
将格式更改为"d"后,效果很好.
After changing the format to 'd' it works fine.
类似地,"Y"代表一年中的第几周-因此我们已将其替换为"y",代表年年
Similarly, 'Y' represents week of the year - so we have replaced that to 'y' which represents year
这篇关于当我们在Java中使用yyyy-MM-dd'T'HH:mm:ssXXX格式时,将填充无效的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!