当前位置:网站首页>LocalDateTime转为Date类型
LocalDateTime转为Date类型
2022-08-01 23:18:00 【ythswzgxlp】
//LocalDateTime是日期处理类,可以设置到年月日时分秒,相当于LocalDate+LocalTime
//通过LocalDateTime.now()获取当前的时间,具体到年月日时分秒
LocalDateTime localDateTime = LocalDateTime.now();
//Zoneld用于标识在Instant和LocalDateTime之间的转换规则,同时也是时区ID
//通过ZoneId的systemDefault获取系统默认时区
ZoneId zoneId = ZoneId.systemDefault();
//LocalDateTime只是能显示本地日期和时间,没有时区
//ZoneIdDateTime要标识一个带时区的日期和时间
//ZonedDateTime相当于LocalDateTime+ZoneId
//通过LocalDateTime的atZone(new ZoneID)把LocalDateTime转换为ZoneDateTime
ZonedDateTime zonedDateTime =localDateTime.atZone(zoneId);
//Instant类用于在应用程序中记录事件的时间戳
//也即是把时间转化为一瞬间
//ZonedDateTime.toInstant是用于把ZonedDateTime转为Instant类型
Instant instant = zonedDateTime.toInstant();
//使用Date.from(new instant)方法,改为Date类型,该日期表示时间轴上与传递的瞬间相同的点。
Date date = Date.from(instant);
System.out.println(date);
对应的ZoneId、ZonedDateTime,Instant还有许多方法获取不同情况下的时间
边栏推荐
- PHP算法之最接近的三数之和
- C语言——分支语句和循环语句
- Chapter 12 End-User Task As Shell Scripts
- perspectiveTransform warpPerspective getPerspectiveTransform findHomography
- 华为无线设备配置双链路冷备份(AP指定配置方式)
- C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
- Special characters & escapes in bat
- PDF转Word有那么难吗?做一个文件转换器,都解决了
- 如何使用pywinauto和pyautogui将动漫小姐姐链接请回家
- 2022/7/31
猜你喜欢
chrome复制一张图片的base64数据
隔离和降级
数据增强--学习笔记(图像类,cnn)
C language - branch statement and loop statement
Use Jenkins for continuous integration, this knowledge point must be mastered
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
C语言——分支语句和循环语句
chrome copies the base64 data of an image
sys_kill system call
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
随机推荐
Special characters & escapes in bat
对于在新标签页中打开的链接,始终使用“noopener”或“noreferrer”
高效工作文档产出归类
When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享
1391D. 505 状压dp
测试岗月薪5-9k,如何实现涨薪到25k?
【SeaTunnel】从一个数据集成组件演化成企业级的服务
How to better understand and do a good job?
6134. 找到离给定两个节点最近的节点-力扣双百代码
从0到1:图文投票小程序设计与研发笔记
研发团队数字化转型实践
6132. 使数组中所有元素都等于零-快速排序法
选择合适的 DevOps 工具,从理解 DevOps 开始
ROS2初级知识(8):Launching启动多节点
Create virtual environments with virtualenv and Virtualenvwrapper virtual environment management tools
xss相关知识点以及从 XSS Payload 学习浏览器解码
Additional Features for Scripting
Chapter 19 Tips and Traps: Common Goofs for Novices
CF1705D Mark and Lightbulbs