0
- 服务器系统是
centos 7
,我的项目是springboot 2.x
-
springboot
内已经在配置文件设置
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: Asia/Shanghai
- 从项目的
controller
返回 Date
类型时候日期时间是对的,代码如下:
@GetMapping("/getJavaDate")
public Date getJavaDate(){
return new Date();
}
-
controller
内通过 new Date()
之后格式化为 yyyy-MM-dd HH:mm:ss
后返回 String
类型,就少了8小时,代码如下:
@GetMapping("/getFormatDate")
public String getFormatDate() throws Exception {
return DatetimeUtil.formatDate(new Date());
}
- 要如何解决这个问题,难道要我手动给
new
出来的时间+8 ?
DatetimeUtil是那个提供的工具呢,这个是不是没设置时区
— 鸿则 · 10月30日