public final class DateTimeUtil extends Object
时间转换解析工具
该工具的主要作用是将LocalDateTime和Date形式的时间互相转换以及将字符串格式的时间和日期时间互相转换。该工具是一个线程安全类的工具,其主要的功能如下:该工具是一个线程安全类的工具
Constructor and Description |
---|
DateTimeUtil() |
Modifier and Type | Method and Description |
---|---|
static LocalDateTime |
date2LocalDateTime(Date date)
将Date转换为 LocalDateTime
|
static String |
format(Date date)
将Date形式的时间格式化为yyyy-MM-dd HH:mm:ss格式的字符串
|
static String |
format(Date date,
String pattern)
将Date形式的时间格式化为 格式化为指定形式的字符串
|
static String |
format(LocalDateTime localDateTime)
将LocalDateTime形式的时间格式化为yyyy-MM-dd HH:mm:ss格式的字符串
|
static String |
format(LocalDateTime localDateTime,
String pattern)
将LocalDateTime形式的时间格式化为 格式化为指定形式的字符串
|
static String |
formatDate(Date date)
将Date形式的时间格式化为yyyy-MM-dd格式的字符串
|
static String |
formatDate(LocalDateTime localDateTime)
将Date形式的时间格式化为yyyy-MM-dd格式的字符串
|
static LocalDateTime |
getLocalDateTime(long milliseconds)
使用从1970-01-01T00:00:00Z的时代开始的毫秒 数获得一个LocalDateTime的实例。
|
static Long |
getTime(Date date)
返回自1970年1月1日以来,由此 Date对象表示的00:00:00 GMT的毫秒 数 。
|
static Long |
getTime(LocalDateTime localDateTime)
返回自1970年1月1日以来,由此LocalDateTime对应的 Date对象表示的00:00:00 GMT的毫秒 数 。
|
static Date |
localDateTime2Date(LocalDateTime localDateTime)
将LocalDateTime转换为 Date
|
static LocalDateTime |
parse(String timeStr)
将字符串解析为LocalDateTime 形式的时间
|
static LocalDateTime |
parse(String timeStr,
String... patterns)
将字符串解析为LocalDateTime 形式的时间
|
static ZoneId |
zoneIdOfChina()
获取北京时间的ZoneId
|
public static ZoneId zoneIdOfChina()
public static LocalDateTime date2LocalDateTime(Date date)
date
- 给定的时间public static Date localDateTime2Date(LocalDateTime localDateTime)
localDateTime
- 给定的时间public static Long getTime(LocalDateTime localDateTime)
localDateTime
- 给定的时间public static Long getTime(Date date)
date
- 给定的时间public static LocalDateTime getLocalDateTime(long milliseconds)
milliseconds
- 从1970-01-01T00:00:00Z的时代开始的毫秒 数public static LocalDateTime parse(String timeStr) throws CustomException
将字符串解析为LocalDateTime 形式的时间
默认采用yyyy-MM-dd HH:mm:ss 或 yyyy-MM-dd HH:mm 或 yyyy-MM-dd 形式解析timeStr
- 需要解析的字符串CustomException
- 解析时出现了问题public static LocalDateTime parse(String timeStr, String... patterns) throws CustomException
timeStr
- 需要解析的字符串patterns
- 解析规则 当未填写解析规则时CustomException
- 解析时出现了问题public static String format(LocalDateTime localDateTime)
localDateTime
- 给定的时间public static String format(LocalDateTime localDateTime, String pattern)
localDateTime
- 给定的时间pattern
- 格式化形式,例如yyyy-MM-dd HH:mm:sspublic static String format(Date date, String pattern)
date
- 给定的时间pattern
- 格式化形式,例如yyyy-MM-dd HH:mm:sspublic static String format(Date date)
date
- 给定的时间public static String formatDate(Date date)
date
- 给定的时间public static String formatDate(LocalDateTime localDateTime)
localDateTime
- 给定的时间Copyright © 2021. All rights reserved.