public class DateUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static DateTimeFormatter |
DATE_FORMATTER |
static DateTimeFormatter |
DATETIME_FORMATTER
java 8 时间格式化
|
static LocalDate |
EPOCH
兼容 java 8
The epoch year
LocalDate, '1970-01-01'. |
static String |
PATTERN_DATE |
static String |
PATTERN_DATETIME |
static String |
PATTERN_TIME |
static DateTimeFormatter |
TIME_FORMATTER |
| Constructor and Description |
|---|
DateUtil() |
| Modifier and Type | Method and Description |
|---|---|
static Duration |
between(Date startDate,
Date endDate)
比较2个 时间差
|
static Period |
between(LocalDate startDate,
LocalDate endDate)
比较2个时间差,跨度比较大,年月日为单位
|
static Duration |
between(Temporal startInclusive,
Temporal endExclusive)
比较2个时间差,跨度比较小
|
static String |
format(Date date,
DateTimeFormatter formatter)
日期格式化
|
static String |
format(Date date,
String pattern)
日期格式化
|
static String |
format(Instant instant,
DateTimeFormatter formatter)
日期格式化
|
static String |
format(TemporalAccessor temporal,
String pattern)
java8 日期格式化
|
static String |
formatDate(Date date)
日期格式化
|
static String |
formatDate(TemporalAccessor temporal)
java8 日期时间格式化
|
static String |
formatDateTime(Date date)
日期时间格式化
|
static String |
formatDateTime(TemporalAccessor temporal)
java8 日期时间格式化
|
static String |
formatTime(Date date)
时间格式化
|
static String |
formatTime(TemporalAccessor temporal)
java8 时间格式化
|
static LocalDateTime |
fromCalendar(Calendar calendar)
转换成java8 时间
|
static LocalDateTime |
fromDate(Date date)
转换成java8 时间
|
static LocalDateTime |
fromInstant(Instant instant)
转换成java8 时间
|
static LocalDateTime |
fromMilliseconds(long milliseconds)
转换成java8 时间
|
static TemporalQuery<Instant> |
instantQuery() |
static boolean |
isAfter(ChronoLocalDateTime<?> self,
ChronoLocalDateTime<?> other)
判断 A 的时间是否在 B 的时间 "之后"
|
static boolean |
isBefore(ChronoLocalDateTime<?> self,
ChronoLocalDateTime<?> other)
判断 A 的时间是否在 B 的时间 "之前"
|
static boolean |
isEqual(ChronoLocalDateTime<?> self,
ChronoLocalDateTime<?> other)
判断 A 的时间是否与 B 的时间 "相同"
|
static Date |
minus(Date date,
TemporalAmount amount)
日期减少时间量
|
static Date |
minusAtUtc(Date date,
TemporalAmount amount)
日期减少时间量
|
static Date |
minusDays(Date date,
long days)
减少天
|
static Date |
minusHours(Date date,
long hours)
减少小时
|
static Date |
minusMillis(Date date,
long millis)
减少毫秒
|
static Date |
minusMinutes(Date date,
long minutes)
减少分钟
|
static Date |
minusMonths(Date date,
int months)
减少月
|
static Date |
minusNanos(Date date,
long nanos)
减少纳秒
|
static Date |
minusSeconds(Date date,
long seconds)
减少秒
|
static Date |
minusWeeks(Date date,
int weeks)
减少周
|
static Date |
minusYears(Date date,
int years)
减少年
|
static <T> T |
parse(CharSequence text,
Locale locale,
String[] parsePatterns,
TemporalQuery<T> query)
将字符串转换为时间
|
static Date |
parse(String dateStr,
DateTimeFormatter format)
将字符串转换为时间
|
static Date |
parse(String dateStr,
String pattern)
将字符串转换为时间
|
static <T> T |
parse(String dateStr,
String pattern,
TemporalQuery<T> query)
将字符串转换为时间
|
static LocalDate |
parseDate(CharSequence dateStr)
将字符串转换为日期
|
static LocalDate |
parseDate(CharSequence dateStr,
DateTimeFormatter formatter)
将字符串转换为时间
|
static LocalDate |
parseDate(CharSequence text,
Locale locale,
String[] parsePatterns)
将字符串转换为日期
|
static LocalDate |
parseDate(CharSequence dateStr,
String pattern)
将字符串转换为时间
|
static LocalDate |
parseDate(CharSequence text,
String[] parsePatterns)
将字符串转换为日期
|
static LocalDateTime |
parseDateTime(CharSequence dateStr)
将字符串转换为时间
|
static LocalDateTime |
parseDateTime(CharSequence dateStr,
DateTimeFormatter formatter)
将字符串转换为时间
|
static LocalDateTime |
parseDateTime(CharSequence text,
Locale locale,
String[] parsePatterns)
将字符串转换为时间
|
static LocalDateTime |
parseDateTime(CharSequence dateStr,
String pattern)
将字符串转换为时间
|
static LocalDateTime |
parseDateTime(CharSequence text,
String[] parsePatterns)
将字符串转换为时间
|
static LocalTime |
parseTime(CharSequence dateStr)
将字符串转换为时间
|
static LocalTime |
parseTime(CharSequence dateStr,
DateTimeFormatter formatter)
将字符串转换为时间
|
static LocalTime |
parseTime(CharSequence text,
Locale locale,
String[] parsePatterns)
将字符串转换为时间
|
static LocalTime |
parseTime(CharSequence dateStr,
String pattern)
将字符串转换为时间
|
static LocalTime |
parseTime(CharSequence text,
String[] parsePatterns)
将字符串转换为时间
|
static Date |
plus(Date date,
TemporalAmount amount)
日期添加时间量
|
static Date |
plusAtUtc(Date date,
TemporalAmount amount)
日期添加时间量
|
static Date |
plusDays(Date date,
long daysToAdd)
添加天
|
static Date |
plusHours(Date date,
long hoursToAdd)
添加小时
|
static Date |
plusMillis(Date date,
long millisToAdd)
添加毫秒
|
static Date |
plusMinutes(Date date,
long minutesToAdd)
添加分钟
|
static Date |
plusMonths(Date date,
int monthsToAdd)
添加月
|
static Date |
plusNanos(Date date,
long nanosToAdd)
添加纳秒
|
static Date |
plusSeconds(Date date,
long secondsToAdd)
添加秒
|
static Date |
plusWeeks(Date date,
int weeksToAdd)
添加周
|
static Date |
plusYears(Date date,
int yearsToAdd)
添加年
|
static Calendar |
toCalendar(LocalDateTime localDateTime)
LocalDateTime 转换成 Calendar.
|
static Date |
toDate(LocalDate localDate)
LocalDate 转换成 date
|
static Date |
toDate(LocalDateTime dateTime)
LocalDateTime 转换成 date
|
static LocalDateTime |
toDateTime(Date date)
Date 转 LocalDateTime
|
static LocalDateTime |
toDateTime(Instant instant)
Instant 转 LocalDateTime
|
static LocalDateTime |
toEndOfDay(LocalDate localDate)
某天结束时间 yyyy-MM-dd 23:59:59
|
static Instant |
toInstant(LocalDateTime dateTime)
LocalDateTime 转 Instant
|
static long |
toMilliseconds(LocalDate localDate)
localDate 转换成毫秒数
|
static long |
toMilliseconds(LocalDateTime localDateTime)
localDateTime 转换成毫秒数
|
static LocalDateTime |
toStartOfDay(LocalDate localDate)
某天开始时间 yyyy-MM-dd 00:00:00
|
public static final String PATTERN_DATETIME
public static final String PATTERN_DATE
public static final String PATTERN_TIME
public static final DateTimeFormatter DATETIME_FORMATTER
public static final DateTimeFormatter DATE_FORMATTER
public static final DateTimeFormatter TIME_FORMATTER
public static final LocalDate EPOCH
The epoch year LocalDate, '1970-01-01'.
public static Date plusYears(Date date, int yearsToAdd)
date - 时间yearsToAdd - 添加的年数public static Date plusMonths(Date date, int monthsToAdd)
date - 时间monthsToAdd - 添加的月数public static Date plusWeeks(Date date, int weeksToAdd)
date - 时间weeksToAdd - 添加的周数public static Date plusDays(Date date, long daysToAdd)
date - 时间daysToAdd - 添加的天数public static Date plusHours(Date date, long hoursToAdd)
date - 时间hoursToAdd - 添加的小时数public static Date plusMinutes(Date date, long minutesToAdd)
date - 时间minutesToAdd - 添加的分钟数public static Date plusSeconds(Date date, long secondsToAdd)
date - 时间secondsToAdd - 添加的秒数public static Date plusMillis(Date date, long millisToAdd)
date - 时间millisToAdd - 添加的毫秒数public static Date plusNanos(Date date, long nanosToAdd)
date - 时间nanosToAdd - 添加的纳秒数public static Date plusAtUtc(Date date, TemporalAmount amount)
date - 时间amount - 时间量public static Date plus(Date date, TemporalAmount amount)
date - 时间amount - 时间量public static Date minusYears(Date date, int years)
date - 时间years - 减少的年数public static Date minusMonths(Date date, int months)
date - 时间months - 减少的月数public static Date minusWeeks(Date date, int weeks)
date - 时间weeks - 减少的周数public static Date minusDays(Date date, long days)
date - 时间days - 减少的天数public static Date minusHours(Date date, long hours)
date - 时间hours - 减少的小时数public static Date minusMinutes(Date date, long minutes)
date - 时间minutes - 减少的分钟数public static Date minusSeconds(Date date, long seconds)
date - 时间seconds - 减少的秒数public static Date minusMillis(Date date, long millis)
date - 时间millis - 减少的毫秒数public static Date minusNanos(Date date, long nanos)
date - 时间nanos - 减少的纳秒数public static Date minusAtUtc(Date date, TemporalAmount amount)
date - 时间amount - 时间量public static Date minus(Date date, TemporalAmount amount)
date - 时间amount - 时间量@Nullable public static String formatDateTime(@Nullable Date date)
date - 时间@Nullable public static String formatDate(@Nullable Date date)
date - 时间@Nullable public static String formatTime(@Nullable Date date)
date - 时间@Nullable public static String format(@Nullable Date date, String pattern)
date - 时间pattern - 表达式@Nullable public static String format(@Nullable Date date, DateTimeFormatter formatter)
date - 时间formatter - 格式化@Nullable public static String format(Instant instant, DateTimeFormatter formatter)
instant - 时间formatter - 格式化public static String formatDateTime(TemporalAccessor temporal)
temporal - 时间public static String formatDate(TemporalAccessor temporal)
temporal - 时间public static String formatTime(TemporalAccessor temporal)
temporal - 时间public static String format(TemporalAccessor temporal, String pattern)
temporal - 时间pattern - 表达式public static Date parse(String dateStr, String pattern)
dateStr - 时间字符串pattern - 表达式public static Date parse(String dateStr, DateTimeFormatter format)
dateStr - 时间字符串format - DateTimeFormatterpublic static <T> T parse(String dateStr, String pattern, TemporalQuery<T> query)
dateStr - 时间字符串pattern - 表达式public static Instant toInstant(LocalDateTime dateTime)
dateTime - 时间public static LocalDateTime toDateTime(Instant instant)
instant - Instantpublic static LocalDateTime toStartOfDay(LocalDate localDate)
localDate - LocalDatepublic static LocalDateTime toEndOfDay(LocalDate localDate)
localDate - LocalDatepublic static LocalDateTime toDateTime(Date date)
date - Datepublic static Date toDate(LocalDateTime dateTime)
dateTime - LocalDateTimepublic static Date toDate(LocalDate localDate)
localDate - LocalDatepublic static Calendar toCalendar(LocalDateTime localDateTime)
public static long toMilliseconds(LocalDateTime localDateTime)
localDateTime - LocalDateTimepublic static long toMilliseconds(LocalDate localDate)
localDate - LocalDatepublic static LocalDateTime fromCalendar(Calendar calendar)
calendar - 日历public static LocalDateTime fromInstant(Instant instant)
instant - Instantpublic static LocalDateTime fromDate(Date date)
date - Datepublic static LocalDateTime fromMilliseconds(long milliseconds)
milliseconds - 毫秒数public static boolean isAfter(ChronoLocalDateTime<?> self, ChronoLocalDateTime<?> other)
self - ChronoLocalDateTimeother - ChronoLocalDateTimepublic static boolean isBefore(ChronoLocalDateTime<?> self, ChronoLocalDateTime<?> other)
self - ChronoLocalDateTimeother - ChronoLocalDateTimepublic static boolean isEqual(ChronoLocalDateTime<?> self, ChronoLocalDateTime<?> other)
self - ChronoLocalDateTimeother - ChronoLocalDateTimepublic static Duration between(Temporal startInclusive, Temporal endExclusive)
startInclusive - 开始时间endExclusive - 结束时间public static Period between(LocalDate startDate, LocalDate endDate)
startDate - 开始时间endDate - 结束时间public static Duration between(Date startDate, Date endDate)
startDate - 开始时间endDate - 结束时间public static LocalDateTime parseDateTime(CharSequence dateStr, String pattern)
dateStr - 时间字符串pattern - 表达式public static LocalDateTime parseDateTime(CharSequence dateStr, DateTimeFormatter formatter)
dateStr - 时间字符串formatter - DateTimeFormatterpublic static LocalDateTime parseDateTime(CharSequence dateStr)
dateStr - 时间字符串public static LocalDateTime parseDateTime(@Nullable CharSequence text, @Nullable String[] parsePatterns)
text - 时间字符串parsePatterns - 时间正则数组public static LocalDateTime parseDateTime(@Nullable CharSequence text, @Nullable Locale locale, @Nullable String[] parsePatterns)
text - 时间字符串locale - LocaleparsePatterns - 时间正则数组public static LocalDate parseDate(CharSequence dateStr, String pattern)
dateStr - 时间字符串pattern - 表达式public static LocalDate parseDate(CharSequence dateStr, DateTimeFormatter formatter)
dateStr - 时间字符串formatter - DateTimeFormatterpublic static LocalDate parseDate(CharSequence dateStr)
dateStr - 时间字符串public static LocalDate parseDate(@Nullable CharSequence text, @Nullable String[] parsePatterns)
text - 时间字符串parsePatterns - 时间正则数组public static LocalDate parseDate(@Nullable CharSequence text, @Nullable Locale locale, @Nullable String[] parsePatterns)
text - 时间字符串locale - LocaleparsePatterns - 时间正则数组public static LocalTime parseTime(CharSequence dateStr, String pattern)
dateStr - 时间字符串pattern - 时间正则public static LocalTime parseTime(CharSequence dateStr, DateTimeFormatter formatter)
dateStr - 时间字符串formatter - DateTimeFormatterpublic static LocalTime parseTime(CharSequence dateStr)
dateStr - 时间字符串public static LocalTime parseTime(@Nullable CharSequence text, @Nullable String[] parsePatterns)
text - 时间字符串parsePatterns - 时间正则数组public static LocalTime parseTime(@Nullable CharSequence text, @Nullable Locale locale, @Nullable String[] parsePatterns)
text - 时间字符串locale - LocaleparsePatterns - 时间正则数组public static <T> T parse(@Nullable
CharSequence text,
@Nullable
Locale locale,
@Nullable
String[] parsePatterns,
TemporalQuery<T> query)
T - 泛型text - 时间字符串locale - LocaleparsePatterns - 时间正则数组query - TemporalQuerypublic static TemporalQuery<Instant> instantQuery()
Copyright © 2024. All rights reserved.