当前位置:网站首页>Convert LocalDateTime to Date type
Convert LocalDateTime to Date type
2022-08-01 23:22:00 【ythswzgxlp】
//LocalDateTime is a date processing class, which can be set to year, month, day, hour, minute and second, which is equivalent to LocalDate+LocalTime//Get the current time through LocalDateTime.now(), specific to the year, month, day, hour, minute and secondLocalDateTime localDateTime = LocalDateTime.now();//Zoneld is used to identify the conversion rule between Instant and LocalDateTime, and is also the time zone ID//Get the system default time zone through the systemDefault of ZoneIdZoneId zoneId = ZoneId.systemDefault();//LocalDateTime can only display the local date and time, no time zone//ZoneIdDateTime to identify a date and time with a time zone//ZonedDateTime is equivalent to LocalDateTime+ZoneId//Convert LocalDateTime to ZoneDateTime through atZone(new ZoneID) of LocalDateTimeZonedDateTime zonedDateTime =localDateTime.atZone(zoneId);//The Instant class is used to record the timestamp of the event in the application// that is, convert the time into a moment//ZonedDateTime.toInstant is used to convert ZonedDateTime to Instant typeInstant instant = zonedDateTime.toInstant();//Use the Date.from(new instant) method to change to Date type, which represents the same point on the time axis as the passed instant.Date date = Date.from(instant);System.out.println(date);The corresponding ZoneId, ZonedDateTime, and Instant have many methods to get the time in different situations
边栏推荐
- ELK log collection
- Chapter 19 Tips and Traps: Common Goofs for Novices
- Chapter 12 End-User Task As Shell Scripts
- 邻接表与邻接矩阵
- excel split text into different rows
- [Recommended books] The first self-driving technology book
- img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)
- qt-faststart installation and use
- drf生成序列化类代码
- How do programmers solve online problems gracefully?
猜你喜欢

隔离和降级

DRF generating serialization class code

6134. Find the closest node to the given two nodes - force double hundred code

访问控制台中的选定节点

中职网络安全竞赛B7比赛部署流程

下载安装 vscode(含汉化、插件的推荐和安装)

Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution

数据机构---第五章树与二叉树---二叉树的概念---应用题

chrome复制一张图片的base64数据

y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
随机推荐
软技能之UML图
高效工作文档产出归类
最短路模板
Is TCP reliable?Why?
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
How to use pywinauto and pyautogui to link the anime lady and sister please go home
excel edit a cell without double clicking
数据增强--学习笔记(图像类,cnn)
程序员如何优雅地解决线上问题?
Department project source code sharing
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
TCP 可靠吗?为什么?
SQL Server (design database--stored procedure--trigger)
添加大量元素时使用 DocumentFragments
6132. 使数组中所有元素都等于零-快速排序法
E - Integer Sequence Fair
excel split text into different rows
The monthly salary of the test post is 5-9k, how to increase the salary to 25k?
Three, mysql storage engine - building database and table operation
excel change cell size