第一种
在配置文件中添加以下内容
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
default-property-inclusion: non_null
第二种
在代码中设置
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置为东八区
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
Date date = new Date();
String dateStr = sdf.format(date);
System.out.println(date);