java这个日期时间的JSON格式模式是什么?
这个Datetime字符串的JsonFormat模式是什么
"2021-02-16Z09:38:35"
它被定义为字符串(ISO日期时间格式)
我把它定义为-
@JsonProperty("lastDT")
@JsonFormat(pattern = "yyyy-MM-dd'Z'HH:mm:ss", shape = JsonFormat.Shape.STRING)
private ZonedDateTime lastDT;
我一直收到一个JSON解析错误
Failed to deserialize java.time.ZonedDateTime: (java.time.DateTimeException) Unable to obtain
ZonedDateTime from TemporalAccessor: {},ISO resolved to 2021-02-16T09:38:35 of type java.time.format.Parsed
# 1 楼答案
ISO 8601格式,拙劣
你问:
似乎有人尝试了标准ISO 8601格式,但失败了
在ISO8601中,字符串的日期部分和时间部分之间应该有一个
T
正确的格式应该是
2021-02-16T09:38:35
,而不是带有T
而不是Z
的2021-02-16Z09:38:35
我建议您教育数据源的发布者如何正确使用ISO 8601
使用
LocalDateTime
,而不是ZonedDateTime
类似
2021-02-16T09:38:35
的字符串表示日期和时间,但没有任何时区或UTC偏移的指示。因此,您应该将代码更改为使用LocalDateTime
而不是ZonedDateTime
祖鲁时间
ISO 8601中使用
Z
表示与UTC的偏移量为0小时分秒。按照航空/军事传统,字母发音为“祖鲁”