Java 这个日期时间的JSON格式模式是什么?

Java 这个日期时间的JSON格式模式是什么?,java,spring,datetime,Java,Spring,Datetime,这个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; 我一直收

这个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
ISO 8601格式,拙劣 你问:

这个Datetime字符串的JsonFormat模式是什么

"2021-02-16Z09:38:35"
“2021-02-16Z09:38:35”

看起来有人尝试使用标准格式,但失败了

在ISO 8601中,字符串的日期部分和时间部分之间应该有一个
T

正确的格式应该是
2021-02-16T09:38:35
,而不是
2021-02-16Z09:38:35
带有
T
,而不是
Z

我建议您教育数据源的发布者如何正确使用ISO 8601

使用
LocalDateTime
,而不是
ZonedDateTime
类似于
2021-02-16T09:38:35的字符串表示日期和时间,但没有任何时区或UTC偏移的指示。因此,您应该将代码更改为使用
LocalDateTime
而不是
ZonedDateTime

String inputCorrected = "2021-02-16Z09:38:35".replace( "Z" , "T" ) ;
LocalDateTime ldt = LocalDateTime.parse( inputCorrected ) ;
祖鲁时间 ISO 8601中使用了
Z
来表示与UTC的偏移量为零小时分秒。根据航空/军事传统,字母发音为“祖鲁”

Instant instant = Instant.now() ;    // Represent a moment as seen in UTC, an offset of zero hours-minutes-seconds from UTC.
String output = instant.toString() ;
2021-02-16T09:38:35Z


谢谢你详细的回答,非常感谢。在将来的任何实现中,我都会记住这一点