zeyfra

@DateTimeFormat

所在包:org.springframework.format.annotation.DateTimeFormat

springframework的注解,一般用来对Date(java.util.Date)类型成员变量的传入的规范化

@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")

@JsonFormat

所在包:com.fasterxml.jackson.annotation.JsonFormat

@JsonFormat是一个时间格式化注解,它只会在类似@ResponseBody往前端返回json数据的时候,才会返回按规定的格式化的时间,直接使用System.out.println()输出的话,仍然是类似“Fri Feb 26 20:05:20 CST 2021”的时间样式。

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

注:

1、@JsonFormat是jackson包里面的一个注解,但spring-boot-starter-web依赖已包含fasterxml依赖,若无spring-boot-starter-web依赖则需引入jackson相关依赖

2、@JsonFormat在序列化时间时是按照国际标准时间GMT进行格式化的,而在国内默认时区使用的是CST时区,两者相差8小时(比国内早8小时)

相关文章:

  • 2021-11-18
  • 2021-04-23
  • 2021-11-06
  • 2021-09-01
  • 2021-06-26
  • 2021-12-15
  • 2021-12-01
  • 2021-12-27
猜你喜欢
  • 2021-03-01
  • 2021-03-16
  • 2021-11-25
  • 2021-12-02
  • 2021-11-14
  • 2018-11-27
  • 2021-08-07
相关资源
相似解决方案