当前位置:网站首页>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
边栏推荐
猜你喜欢

【参营经历贴】2022网安夏令营

解决端口占用

img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)

伸展树的特性及实现

【C语言进阶】文件操作(二)

The monthly salary of the test post is 5-9k, how to increase the salary to 25k?

深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练

cmd command

Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions

文件查询匹配神器 【glob.js】 实用教程
随机推荐
How to better understand and do a good job?
如何更好的理解的和做好工作?
Chapter 11 Working with Dates and Times
A. Doremy‘s IQ-- Codeforces Round #808 (Div. 1)
美赞臣EDI 940仓库装运订单详解
深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
ELK日志采集
excel remove all carriage return from a cell
【好书推荐】第一本无人驾驶技术书
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
云原生DevOps环境搭建
excel split text into different rows
nodejs--process
中职网络安全竞赛B7比赛部署流程
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)
numpy.around
[Recommended books] The first self-driving technology book
Additional Features for Scripting
6133. Maximum number of packets