[转]LocalDate转Date类型

发布时间 2023-09-26 14:17:32作者: dirgo

原文地址:LocalDate转Date类型 - 简书

1.8LocalDateDate之间的相互转换需要借助Date中新增的from()toInstant()

LocalDate 转Date

1.需要先将LocalDate转为LocalDateTime

LocalDate.atStartOfDay()

2. 获取 Instance,需要指定时区,这里使用系统默认

LocalDateTime.atZone(ZoneId.systemDefault()).toInstant()

3.转化

Date.from()

连起来就是

Date.from(LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())

Date转LocalDate

new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()


作者:马木木
链接:https://www.jianshu.com/p/d8aec3ec76fd
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
 
其他参考文章:
Java8 LocalDate、Date、LocalDateTime、时间戳的转换 - 简书