当前位置:网站首页>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 安装使用
- Chapter 12 End-User Task As Shell Scripts
- [Recommended books] The first self-driving technology book
- What is CICD excuse me
- 【参营经历贴】2022网安夏令营
- npm npm
- 如何使用pywinauto和pyautogui将动漫小姐姐链接请回家
- 解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”
- Avoid hidden text when loading fonts
- Postman batch test interface detailed tutorial
猜你喜欢
随机推荐
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
检查点是否在矩形内
excel split text into different rows
论文解读(GSAT)《Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism》
Create virtual environments with virtualenv and Virtualenvwrapper virtual environment management tools
IDEA common plugins
Calculate the midpoint between two points
6132. 使数组中所有元素都等于零-快速排序法
【SeaTunnel】从一个数据集成组件演化成企业级的服务
[C language advanced] file operation (2)
sys_kill系统调用
文件查询匹配神器 【glob.js】 实用教程
excel change cell size
excel change cell size
Error creating bean with name ‘dataSource‘:Unsatisfied dependency expressed through field ‘basicPro
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)
DRF generating serialization class code
6134. Find the closest node to the given two nodes - force double hundred code
Jmeter是什么
PostgreSQL 基础--常用命令





![[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环](/img/63/16de443caf28644d79dc6e6889e5dd.png)



