当前位置:网站首页>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还有许多方法获取不同情况下的时间
边栏推荐
- qt-faststart installation and use
- excel clear format
- 问题解决方式了
- From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
- cmd指令
- 6134. Find the closest node to the given two nodes - force double hundred code
- excel edit a cell without double clicking
- 部门项目源码分享
- 毕业作业
- [C language advanced] file operation (2)
猜你喜欢

华为无线设备配置双链路冷备份(AP指定配置方式)

E - Integer Sequence Fair

PDF转Word有那么难吗?做一个文件转换器,都解决了

ROS2初级知识(8):Launching启动多节点

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

复现gallerycms字符长度限制短域名绕过

From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs

From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program

分享10套开源免费的高品质源码,免费源码下载平台
![[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环](/img/63/16de443caf28644d79dc6e6889e5dd.png)
[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环
随机推荐
2022年最新河北建筑八大员(机械员)模拟考试题库及答案
添加大量元素时使用 DocumentFragments
excel remove all carriage return from a cell
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu
drf生成序列化类代码
When using DocumentFragments add a large number of elements
怎样做才能让这条SQL变成一条危险的SQL?
JS 数组去重(含简单数组去重、对象数组去重)
6132. All the elements in the array is equal to zero - quick sort method
npm npm
华为无线设备配置双链路冷备份(AP指定配置方式)
CF1705D Mark and Lightbulbs
解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”
Avoid , ,
, and tagsA. Doremy‘s IQ-- Codeforces Round #808 (Div. 1)
Always use "noopener" or "noreferrer" for links that open in a new tab
避免使用 <b>、<i>、<s> 和 <u> 标签
Use Jenkins for continuous integration, this knowledge point must be mastered
What is CICD excuse me
excel vertical to horizontal