[转]Java 新日期api 的LocalDate 与 旧的 Date类型的转换

原文地址: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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
 
其他参考文章:
posted @   dirgo  阅读(163)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2022-09-26 docker 离线部署前端项目,附防火墙相关操作
2022-09-26 [转]Docker报错“Dockerfile parse error line 1: FROM requires either one or three arguments”
2022-09-26 [转]Dockerfile:ADD VS COPY (结论:建议都使用COPY)
2022-09-26 docker 常用命令
2019-09-26 [转]JRebel 热部署激活教程
2015-09-26 1.6实践与练习
点击右上角即可分享
微信分享提示