服务器时区和JAVA进程时区不一致问题解决
服务器时间
[root@product product]# date -R
Thu, 21 Apr 2022 15:00:44 +0800
[root@product product]# date "+%Y-%m-%d %H:%M:%S"
2022-04-21 15:01:09
java进程时间
接收时间:2022-04-21 02:53:49.97
解决方法
/**
* @Classname TimeZoneStartup
* @Description
* @Date 2022/4/21 14:56
*/
@Component
public class TimeZoneStartup {
/**
* 设置时区
*/
@PostConstruct
public void init(){
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
}
}