java 关于时间返回结果与参数的注解@DatetimeFormat和@JsonFormat

时间是一个比较常用的类型。显示的时候通常是以String显示的。如果前端参数,前端人员也希望用String作为参数

常用注解

@DatetimeFormat是将String转换成Date,一般前台给后台传值时用


@JsonFormat(pattern="yyyy-MM-dd") 将Date转换成String 一般后台传值给前台时

@JsonFormat会让时间以0区时间显示。如果直接使用会少了8小时(我所在的是北京时区)修改为

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

 

posted @ 2018-04-03 14:23  钟政123  阅读(18921)  评论(0编辑  收藏  举报