JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Element 中的组件 DatePicker 传递后台的时间格式为UTC时区

wys521 2024-11-13 15:06:18 精选教程 23 ℃ 0 评论

1.Element 中的组件 DatePicker 传递后台的时间格式为UTC时区 造成LocalDateTime接收时间慢了8小时

2.如果用LocalDateTime 接受不能直接用时间戳来传递。

3.用时间戳传递,时间戳没有时区的概念 springboot用Date接受

@DateTimeFormat(pattern="yyyy-mm-dd HH:mm:ss")

private Date date;

4.获取到Date后进行LocalDateTime转换

Date date = new Date();

Instant instant = date.toInstant();

ZoneId zoneId = ZoneId.systemDefault();

LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

5.LocalDateTime转Date传递给前端

LocalDateTime localDateTime = LocalDateTime.now();

ZoneId zone = ZoneId.systemDefault();

Instant instant = localDateTime.atZone(zone).toInstant();

Date date = Date.from(instant);

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表