gpt4 book ai didi

java - Jax-RS JsonFormat 日期未知 39

转载 作者:行者123 更新时间:2023-11-30 06:21:40 25 4
gpt4 key购买 nike

FilmEvent.java

    import java.util.Date;

@AllArgsConstructor(access=AccessLevel.PUBLIC)
public class FilmEvent {
@Getter
private String id;

@Getter
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd,HH:mm", timezone="CET")
private Date date;

@Getter
private String[] attributes;

@Getter
private boolean soldOut;

}

我的记录

FilmEvent event = new FilmEvent("334",  new Date(2018,1,1,12,44), null, false);

我在 Firefox 中的结果

date:"3918-02-01,12:44"

问题是,为什么是 3918-02-01?以及如何修复它;

最佳答案

根据JavaDocDate 构造函数将年份参数设为 year-1900,因此您的初始年份将按 1900 添加。

JavaDoc:

year - the year minus 1900.
month - the month between 0-11.
date - the day of the month between 1-31.
hrs - the hours between 0-23.
min - the minutes between 0-59.

这也是很久以前就被弃用的。我建议使用 here 中的 LocalDateTime

关于java - Jax-RS JsonFormat 日期未知 39,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48021321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com