用word做旅游网站,网页搭建服务平台,淄博网站外包,seo的培训课程Catalog 时间属性格式问题一、需求二、怎么使用 时间属性格式问题
一、需求
对于表中时间字段#xff0c;后端创建对应的实体类的时间属性需要设定格式#xff08;默认的格式不方便阅读#xff09;#xff0c;再返回给前端。
二、怎么使用 导入jackson相关的坐标#x… Catalog 时间属性格式问题一、需求二、怎么使用 时间属性格式问题
一、需求
对于表中时间字段后端创建对应的实体类的时间属性需要设定格式默认的格式不方便阅读再返回给前端。
二、怎么使用 导入jackson相关的坐标SpringBoot工程中一般默认在web的starter包里面。 !-- Jackson Annotations --dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-annotations/artifactIdversion2.12.3/version !-- 确保版本与其他Jackson依赖一致 --/dependency!-- Jackson Core --dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-core/artifactIdversion2.12.3/version/dependency!-- Jackson Databind --dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion2.12.3/version/dependency使用JsonFormat注解,在实体类的时间属性上面添加(“设置日期的显示格式和时区”)y\m\d\h\m\s分别代别年月日时分秒 JsonFormat(pattern yyyy-MM-dd HH:mm:ss, timezone GMT8)private Date createTime;或者在SpringBoot的配置文件中配置 spring:jackson:date-format: yyyy-mm-dd HH:mm:sstime-zone: GMT8tips:时间戳格式转换 /*** 时间格式刷* return*/public static String dateBrush(){//获取格式刷SimpleDateFormat simpleDateFormat new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);long currentTime System.currentTimeMillis();//将时间戳转换为时间类型Date date new Date(currentTime);//调用格式刷String dataStr simpleDateFormat.format(date);return dataStr;}