当前位置:网站首页>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还有许多方法获取不同情况下的时间
边栏推荐
猜你喜欢

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

What is CICD excuse me

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

cmd command

TCP 可靠吗?为什么?

Use Jenkins for continuous integration, this knowledge point must be mastered

sys_kill系统调用

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

10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享

论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
随机推荐
Chapter 12 End-User Task As Shell Scripts
From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program
ping no reply
基于JAX的激活函数、softmax函数和交叉熵函数
From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
华为无线设备配置双链路冷备份(AP指定配置方式)
【C语言进阶】文件操作(二)
img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)
y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)
cmd指令
CF1705D Mark and Lightbulbs
【C补充】链表专题 - 单向链表
npm npm
IDEA常用插件
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
qt-faststart 安装使用
移动端人脸风格化技术的应用
problem solved
下载安装 vscode(含汉化、插件的推荐和安装)
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu