在接口测试的时候,发现时间少了8小时。通过网上各个博客发现了两个问题。
首先是显示在页面的时间格式(date)和我从api接口里测试的也不同。
时间格式的处理,前端的时间显示2020-07-13T16:02:00.000+0000
在后端添加@JsonFormat
@JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.1</version>
<scope>compile</scope>
</dependency>
或 前端js 更改前端样式: 参考