可以使用LocalDateTime的atZone()方法将其转换为ZonedDateTime,然后使用toInstant()方法将其转换为Instant,最后使用Date.from()方法将其转换为Date。

例如:

LocalDateTime localDateTime = LocalDateTime.now();
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
Instant instant = zonedDateTime.toInstant();
Date date = Date.from(instant);

注意,从Java 8开始,Date和时间相关的类已被弃用,建议使用新的java.time包中的类来处理日期和时间。

java spring localDateTime 转 date

原文地址: https://www.cveoy.top/t/topic/fiSn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录