700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > java 设置timezone_如何设置系统时区作为 @JsonFormat timezone

java 设置timezone_如何设置系统时区作为 @JsonFormat timezone

时间:2022-09-22 12:13:32

相关推荐

java 设置timezone_如何设置系统时区作为 @JsonFormat timezone

各位大佬:

从数据库查到的时间使用jackson的@JsonFormat进行格式化:

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")

private Date beginTime;

由于GMT+8这种常量不利于国际化,所以我想使用系统时区作为timezone。

我的方法:

1 使用默认时区

@JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "HH:mm",timezone = JsonFormat.DEFAULT_TIMEZONE)

private Date timeQuantumBegin;

2 配置objectMapper,设置系统时区

@Autowired

public void configureJackson(ObjectMapper objectMapper) {

objectMapper.setTimeZone(TimeZone.getDefault());

}

但是效果还是达不到,差了八个小时。请问是我哪里做的不对吗?

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。