当前位置:网站首页>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
边栏推荐
- 云原生DevOps环境搭建
- SQL Server (design database--stored procedure--trigger)
- What can be done to make this SQL into a dangerous SQL?
- 6134. Find the closest node to the given two nodes - force double hundred code
- 毕业作业
- LocalDateTime转为Date类型
- excel cell contian two words, seperated by a slash
- IDEA common plugins
- Secondary Vocational Network Security Competition B7 Competition Deployment Process
- The monthly salary of the test post is 5-9k, how to increase the salary to 25k?
猜你喜欢

nodejs--process

Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历

y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)

sys_kill系统调用

Access the selected node in the console

System availability: 3 9s, 4 9s in SRE's mouth... What is it?

美赞臣EDI 940仓库装运订单详解

数据分析04

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

PDF转Word有那么难吗?做一个文件转换器,都解决了
随机推荐
避免使用 <b>、<i>、<s> 和 <u> 标签
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
Loading configuration of Nacos configuration center
Building a cloud-native DevOps environment
excel change cell size
检查点是否在矩形内
Oracle database is set to read-only and read-write
从0到1:图文投票小程序设计与研发笔记
System availability: 3 9s, 4 9s in SRE's mouth... What is it?
JS 数组去重(含简单数组去重、对象数组去重)
Solve the port to take up
PostgreSQL 基础--常用命令
Three, mysql storage engine - building database and table operation
excel split text into different rows
高效工作文档产出归类
sys_kill系统调用
C语言——分支语句和循环语句
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu
欧拉路径与欧拉回路