Springboot配置时间格式


方法一:
可以在apllication.property加入下面配置就可以

时间戳统一转换

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

方法二:

@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date createdDate;

@JsonFormat(timezone = "GMT+8", pattern = "yyyyMMddHHmmss")
private Date createTime;

引入依赖:

复制代码

        
            com.fasterxml.jackson.core
            jackson-annotations
            2.9.0
        
        
        
            org.springframework
            spring-context
            5.1.5.RELEASE
            compile
        

复制代码
方法三:
可以在apllication.yml加入下面配置就可以

时间戳统一转换

spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
注意:
@JsonIgnoreProperties此注解是类注解,作用是json序列化时将java bean中的一些属性忽略掉,序列化和反序列化都受影响。
@JsonIgnoreProperties(value = { "word" }) 。
@JsonIgnore此注解用于属性或者方法上(最好是属性上),作用和上面的@JsonIgnoreProperties一样。
@JsonSerialize此注解用于属性或者getter方法上,用于在序列化时嵌入我们自定义的代码,比如序列化一个double时在其后面限制两位小数点。
@JsonSerialize(using = CustomDoubleSerialize.class)
@JsonDeserialize此注解用于属性或者setter方法上。
用于在反序列化时可以嵌入我们自定义的代码,类似于上面的
@JsonSerialize
@JsonDeserialize(using = CustomDateDeserialize.class)

参考链接:

相关