1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > data spring 指定时区_SpringBoot 相关时区(TimeZone)设置

data spring 指定时区_SpringBoot 相关时区(TimeZone)设置

时间:2019-05-03 10:37:12

相关推荐

data spring 指定时区_SpringBoot 相关时区(TimeZone)设置

1.启动文件中的TimeZone设置:

public static void main(String[] args) {

TimeZone timeZone = TimeZone.getTimeZone("UTC");

TimeZone.setDefault(timeZone);

SpringApplication.run(MatrixApplication.class, args);

}

只对运行的console日志的时间影响。

2.数据连接字符串

jdbc:mysql://localhost:3306/gmall?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

对与读取到的时间会自动减去+8小时插入到数据库(如果数据库设置的utc+8的北京时间的),查询的时候

3.springboot 接口时间字段返回配置

spring.jackson.date-format: yyyy-MM-dd HH:mm:ss

spring.jackson.time-zone: GMT+8

对springboot rest接口时间字段生效。

时间格式化时区设置

如果没有设置会使用程序运行系统的默认的时区。

SimpleDateFormat dd=new SimpleDateFormat("yyyy/MM/dd");

log.info(TimeZone.getDefault().toString()); // 系统默认时区

log.info(dd.getTimeZone().toString());//SimpleDateFormat 使用的时区

log.info(dd.parse(dstr1).toS

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。