当前位置:网站首页>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
边栏推荐
- 对于在新标签页中打开的链接,始终使用“noopener”或“noreferrer”
- Chapter 12 End-User Task As Shell Scripts
- 中职网络安全竞赛B7比赛部署流程
- Solve the port to take up
- excel split text into different rows
- 基于JAX的激活函数、softmax函数和交叉熵函数
- [LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph
- sys_kill system call
- SQL Server(设计数据库--存储过程--触发器)
- D - Linear Probing- 并查集
猜你喜欢
从0到100:招生报名小程序开发笔记
chrome copies the base64 data of an image
文件查询匹配神器 【glob.js】 实用教程
美赞臣EDI 940仓库装运订单详解
System availability: 3 9s, 4 9s in SRE's mouth... What is it?
DRF generating serialization class code
论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
程序员如何优雅地解决线上问题?
drf生成序列化类代码
测试岗月薪5-9k,如何实现涨薪到25k?
随机推荐
Chapter 12 End-User Task As Shell Scripts
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
【SeaTunnel】从一个数据集成组件演化成企业级的服务
npm npm
sys_kill系统调用
Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历
加载字体时避免隐藏文本
Avoid , ,
, and tags文件查询匹配神器 【glob.js】 实用教程
color transparency parameter
问题解决方式了
qt-faststart installation and use
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu
PostgreSQL Basics--Common Commands
A. Doremy‘s IQ-- Codeforces Round #808 (Div. 1)
深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
vscode hide menu bar
从0到1:图文投票小程序设计与研发笔记
论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
The monthly salary of the test post is 5-9k, how to increase the salary to 25k?