Springboot配置时间格式
SpringBoot配置 时间 格式
2023-09-14 08:57:06 时间
方法一:
可以在apllication.property
加入下面配置就可以
1 #时间戳统一转换 2 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss 3 spring.jackson.time-zone=GMT+8
方法二:
1 @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd") 2 @DateTimeFormat(pattern="yyyy-MM-dd") 3 private Date createdDate;
1 @JsonFormat(timezone = "GMT+8", pattern = "yyyyMMddHHmmss") 2 private Date createTime;
引入依赖:
1 <!--使用JsonFormat注解--> 2 <dependency> 3 <groupId>com.fasterxml.jackson.core</groupId> 4 <artifactId>jackson-annotations</artifactId> 5 <version>2.9.0</version> 6 </dependency> 7 <!--使用DataFormat注解--> 8 <dependency> 9 <groupId>org.springframework</groupId> 10 <artifactId>spring-context</artifactId> 11 <version>5.1.5.RELEASE</version> 12 <scope>compile</scope> 13 </dependency>
方法三:
可以在apllication.yml
加入下面配置就可以
1 #时间戳统一转换 2 spring: 3 jackson: 4 date-format: yyyy-MM-dd HH:mm:ss 5 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)
参考:https://blog.csdn.net/qq_32447301/article/details/81712266
方法一:
可以在apllication.property
加入下面配置就可以
#时间戳统一转换
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
- 1
- 2
- 3
方法二:
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date createdDate;
- 1
- 2
- 3
@JsonFormat(timezone = "GMT+8", pattern = "yyyyMMddHHmmss")
private Date createTime;
- 1
- 2
方法三:
可以在apllication.yml
加入下面配置就可以
#时间戳统一转换
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
相关文章
- springboot的自动化配置是什么_spring三种配置方式
- springboot启动原理总结_Springboot启动流程
- SpringBoot的启动流程_springboot启动卡住了
- Spring学习笔记(三十三)——SpringBoot集成Swagger
- SpringBoot 配置Mybatis两种方式
- idea配置springboot热部署终极解决办法,解决热部署失效问题
- 自定义SpringBoot自动配置类
- 手把手教你springboot集成微信支付
- mybatisplus自定义拦截器_springboot自定义拦截器
- idea springboot项目搭建_idea社区版配置Tomcat
- springboot idea 热部署配置
- Alibaba最新推出Spring+SpringBoot+SpringCloud全家桶诛仙手册
- SpringBoot单元测试:MockMvc的自动配置
- springboot 整合 seata 分布式事务
- SpringBoot 统一结果集处理器
- SpringBoot文件上传、下载、删除
- JAVA springboot 添加全局异常的处理
- Spring-Data-Redis快速使用(SpringBoot)
- Springboot整合Rabbitmq,Direct、Fanout、Topic
- 微信小程序+SpringBoot实现文件上传与下载
- 毕业设计So Easy:SpringBoot+Vue图书阅读和管理系统(前端+后端+小程序端)
- Springboot配置不同的application.yml环境
- SpringBoot之starter(R)详解编程语言
- Springboot+Thymeleaf+layui框架的配置与使用详解编程语言
- eclipse中,将springboot项目打成jar包详解编程语言
- springboot设置接口超时详解编程语言
- springboot使用jpa+mongodb时,xxxRepository不能Autowired的问题详解编程语言
- SpringBoot profles配置多环境详解编程语言
- springboot自带定时器实现定时任务的开启关闭以及定时时间可以配置详解编程语言
- springboot-配置多个数据源详解编程语言