public class DateTimeTools extends Object
| Modifier and Type | Method and Description |
|---|---|
static LocalDate |
endDateOfYear(int year)
获取指定年份的结束日期
|
static YearQuarter |
getQuarter(Calendar date)
获取指定日期所在季度
|
static YearQuarter |
getQuarter(Date date)
Deprecated.
此方法使用系统默认时区,不建议使用。
请使用
#of(Date,ZoneId)、#of(Date,TimeZone) 或其它工厂方法 |
static YearQuarter |
getQuarter(Date date,
TimeZone timeZone)
根据指定日期,判断日期所在的年份与季度,创建
YearQuarter 实例 |
static YearQuarter |
getQuarter(Date date,
ZoneId timeZone)
根据指定日期,判断日期所在的年份与季度,创建
YearQuarter 实例 |
static YearQuarter |
getQuarter(int year,
Month month)
获取指定年月所在季度
|
static YearQuarter |
getQuarter(LocalDate date)
获取指定日期所在季度
|
static Quarter |
getQuarter(Month month)
获取指定月份所在季度
|
static YearQuarter |
getQuarter(YearMonth yearMonth)
获取指定年月所在季度
|
static boolean |
isFuture(Calendar calendar)
判断指定日期时间是否在将来
|
static boolean |
isFuture(Date date)
判断指定日期时间是否在将来
|
static boolean |
isFuture(Instant instant)
判断指定时刻是否在将来
|
static boolean |
isFuture(LocalDate date)
判断指定日期是否在将来
|
static boolean |
isFuture(LocalDateTime dateTime)
判断指定日期时间是否在将来
|
static boolean |
isFuture(long timeMillis)
判断指定时间戳是否在将来
|
static boolean |
isFuture(ZonedDateTime dateTime)
判断指定日期时间是否在将来
|
static boolean |
isLeapYear(int year)
判断指定年份是否为闰年
|
static boolean |
isPast(Calendar calendar)
判断指定日期时间是否在过去
|
static boolean |
isPast(Date date)
判断指定日期时间是否在过去
|
static boolean |
isPast(Instant instant)
判断指定时刻是否在过去
|
static boolean |
isPast(LocalDate date)
判断指定日期是否在过去
|
static boolean |
isPast(LocalDateTime dateTime)
判断指定日期时间是否在过去
|
static boolean |
isPast(long timeMillis)
判断指定时间戳是否在过去
|
static boolean |
isPast(ZonedDateTime dateTime)
判断指定日期时间是否在过去
|
static LocalDate |
startDateOfYear(int year)
获取指定年份的开始日期
|
static LocalDateTime |
startOfNextDate(LocalDate date)
获取指定日期的第二天的开始时间
|
static ZonedDateTime |
startOfNextDate(LocalDate date,
ZoneId zone)
获取指定日期的第二天的开始时间
|
static Date |
toDate(Calendar calendar)
|
static Date |
toDate(Instant instant)
|
static Date |
toDate(LocalDate localDate,
LocalTime localTime,
ZoneId zone)
|
static Date |
toDate(LocalDateTime localDateTime,
ZoneId zone)
使用指定时区,将
LocalDateTime 对象转换为 Date 对象 |
static Date |
toDate(long timeMillis)
将时间戳转换为
Date 对象 |
static Date |
toDate(ZonedDateTime zonedDateTime)
将
ZonedDateTime 对象转换为 Date 对象 |
static com.google.common.collect.Range<LocalDateTime> |
toDateTimeRange(LocalDate date)
获取指定日期的时间范围
|
static com.google.common.collect.Range<ZonedDateTime> |
toDateTimeRange(LocalDate date,
ZoneId zone)
获取指定日期的时间范围
|
static com.google.common.collect.Range<LocalDateTime> |
toDateTimeRange(com.google.common.collect.Range<LocalDate> dateRange)
将指定日期范围转为日期时间范围
|
static com.google.common.collect.Range<ZonedDateTime> |
toDateTimeRange(com.google.common.collect.Range<LocalDate> dateRange,
ZoneId zone)
将指定日期范围转为日期时间范围
|
static Instant |
toInstant(Calendar calendar)
|
static Instant |
toInstant(Date date)
|
static Instant |
toInstant(LocalDateTime localDateTime,
ZoneId zone)
使用指定时区,将
LocalDateTime 对象转换为 Instant 对象 |
static Instant |
toInstant(long timeMillis)
将时间戳转换为
Instant 对象 |
static Instant |
toInstant(ZonedDateTime zonedDateTime)
将
ZonedDateTime 对象转换为 Instant 对象 |
static LocalDateTime |
toLocalDateTime(Calendar calendar,
TimeZone zone)
获取
Calendar 所表示的时间戳,在指定时区的地区时间。 |
static LocalDateTime |
toLocalDateTime(Calendar calendar,
ZoneId zone)
获取
Calendar 所表示的时间戳,在指定时区的地区时间。 |
static LocalDateTime |
toLocalDateTime(Date dateTime,
TimeZone timeZone)
获取
Date 所表示的时间戳,在指定时区的地区时间。 |
static LocalDateTime |
toLocalDateTime(Date dateTime,
ZoneId zone)
获取
Date 所表示的时间戳,在指定时区的地区时间。 |
static LocalDateTime |
toLocalDateTime(long timeMillis,
ZoneId zone)
获取时间戳在指定时区的地区时间。
|
static LocalDateTime |
toLocalDateTime(ZonedDateTime zonedDateTime,
ZoneId zone)
获取
ZonedDateTime 所表示的时间戳,在指定时区的地区时间。 |
static String |
toMonthStringM(int monthValue) |
static String |
toMonthStringM(Month month) |
static String |
toMonthStringMM(int monthValue) |
static String |
toMonthStringMM(Month month) |
static String |
toYearString(int year) |
static String |
toYearString(Year year) |
static ZonedDateTime |
toZonedDateTime(Calendar calendar)
|
static ZonedDateTime |
toZonedDateTime(Calendar calendar,
TimeZone zone)
使用指定的时区,将
Calendar 对象转换为 ZonedDateTime 对象。 |
static ZonedDateTime |
toZonedDateTime(Calendar calendar,
ZoneId zone)
使用指定的时区,将
Calendar 对象转换为 ZonedDateTime 对象。 |
static ZonedDateTime |
toZonedDateTime(Date dateTime,
TimeZone timeZone)
获取
Date 所表示的时间戳,在指定时区的地区时间。 |
static ZonedDateTime |
toZonedDateTime(Date dateTime,
ZoneId zone)
获取
Date 所表示的时间戳,在指定时区的地区时间。 |
static ZonedDateTime |
toZonedDateTime(LocalDateTime localDateTime,
ZoneId zone)
创建带时区的地区时间
|
static ZonedDateTime |
toZonedDateTime(long timeMillis,
ZoneId zone)
获取时间戳在指定时区的地区时间。
|
public static String toYearString(int year)
public static String toMonthStringM(int monthValue)
public static String toMonthStringMM(int monthValue)
public static Date toDate(long timeMillis)
Date 对象timeMillis - 时间戳Date 对象public static Date toDate(ZonedDateTime zonedDateTime)
ZonedDateTime 对象转换为 Date 对象zonedDateTime - ZonedDateTime 对象Date 对象public static Date toDate(LocalDateTime localDateTime, ZoneId zone)
LocalDateTime 对象转换为 Date 对象localDateTime - LocalDateTime 对象zone - 时区Date 对象public static Instant toInstant(long timeMillis)
Instant 对象timeMillis - 时间戳Instant 对象public static Instant toInstant(ZonedDateTime zonedDateTime)
ZonedDateTime 对象转换为 Instant 对象zonedDateTime - ZonedDateTime 对象Instant 对象public static Instant toInstant(LocalDateTime localDateTime, ZoneId zone)
LocalDateTime 对象转换为 Instant 对象localDateTime - LocalDateTime 对象zone - 时区Instant 对象public static ZonedDateTime toZonedDateTime(long timeMillis, ZoneId zone)
传入不同 ZoneId,获取到的 ZonedDateTime 对象实际上还是同一时间戳,
只是不同时区的表示。
timeMillis - 时间戳zone - 时区public static ZonedDateTime toZonedDateTime(Date dateTime, ZoneId zone)
Date 所表示的时间戳,在指定时区的地区时间。
传入不同 ZoneId,获取到的 ZonedDateTime 对象实际上还是同一时间戳,
只是不同时区的表示。
dateTime - Date 对象zone - 时区public static ZonedDateTime toZonedDateTime(Date dateTime, TimeZone timeZone)
Date 所表示的时间戳,在指定时区的地区时间。
传入不同 ZoneId,获取到的 ZonedDateTime 对象实际上表示的还是还是同一时间戳的时间,
只是不同时区的表示。
dateTime - Date 对象timeZone - 时区public static ZonedDateTime toZonedDateTime(Calendar calendar)
calendar{@link - Calendar} 对象ZonedDateTime 对象public static ZonedDateTime toZonedDateTime(Calendar calendar, ZoneId zone)
Calendar 对象转换为 ZonedDateTime 对象。calendar - Calendar 对象zone - 时区ZonedDateTime 对象public static ZonedDateTime toZonedDateTime(Calendar calendar, TimeZone zone)
Calendar 对象转换为 ZonedDateTime 对象。calendar - Calendar 对象zone - 时区ZonedDateTime 对象public static ZonedDateTime toZonedDateTime(LocalDateTime localDateTime, ZoneId zone)
localDateTime - 地区时间zone - 时区public static LocalDateTime toLocalDateTime(long timeMillis, ZoneId zone)
timeMillis - 时间戳zone - 时区public static LocalDateTime toLocalDateTime(Date dateTime, ZoneId zone)
Date 所表示的时间戳,在指定时区的地区时间。dateTime - Date 对象zone - 时区public static LocalDateTime toLocalDateTime(Date dateTime, TimeZone timeZone)
Date 所表示的时间戳,在指定时区的地区时间。dateTime - Date 对象timeZone - 时区public static LocalDateTime toLocalDateTime(Calendar calendar, ZoneId zone)
Calendar 所表示的时间戳,在指定时区的地区时间。calendar - Calendar 对象zone - 时区public static LocalDateTime toLocalDateTime(Calendar calendar, TimeZone zone)
Calendar 所表示的时间戳,在指定时区的地区时间。calendar - Calendar 对象zone - 时区public static LocalDateTime toLocalDateTime(ZonedDateTime zonedDateTime, ZoneId zone)
ZonedDateTime 所表示的时间戳,在指定时区的地区时间。zonedDateTime - ZonedDateTime 对象zone - 时区@Deprecated public static YearQuarter getQuarter(Date date)
#of(Date,ZoneId)、#of(Date,TimeZone) 或其它工厂方法date - 日期public static YearQuarter getQuarter(Date date, ZoneId timeZone)
YearQuarter 实例date - 日期timeZone - 时区YearQuarter 实例public static YearQuarter getQuarter(Date date, TimeZone timeZone)
YearQuarter 实例date - 日期timeZone - 时区YearQuarter 实例public static YearQuarter getQuarter(Calendar date)
date - 日期public static Quarter getQuarter(Month month)
month - 月份public static YearQuarter getQuarter(int year, Month month)
year - 年month - 月public static YearQuarter getQuarter(YearMonth yearMonth)
yearMonth - 年月public static YearQuarter getQuarter(LocalDate date)
date - 日期public static LocalDate startDateOfYear(int year)
year - 年份public static LocalDate endDateOfYear(int year)
year - 年份public static LocalDateTime startOfNextDate(LocalDate date)
date - 日期public static ZonedDateTime startOfNextDate(LocalDate date, ZoneId zone)
date - 日期zone - 时区public static boolean isFuture(Date date)
date - 日期时间public static boolean isFuture(Calendar calendar)
calendar - 日期时间public static boolean isFuture(Instant instant)
instant - 时刻public static boolean isFuture(long timeMillis)
timeMillis - 时间戳public static boolean isFuture(LocalDate date)
date - 日期public static boolean isFuture(LocalDateTime dateTime)
dateTime - 日期时间public static boolean isFuture(ZonedDateTime dateTime)
dateTime - 日期时间public static boolean isPast(Date date)
date - 日期时间public static boolean isPast(Calendar calendar)
calendar - 日期时间public static boolean isPast(Instant instant)
instant - 时刻public static boolean isPast(long timeMillis)
timeMillis - 时间戳public static boolean isPast(LocalDate date)
date - 日期public static boolean isPast(LocalDateTime dateTime)
dateTime - 日期时间public static boolean isPast(ZonedDateTime dateTime)
dateTime - 日期时间public static com.google.common.collect.Range<LocalDateTime> toDateTimeRange(LocalDate date)
date - 日期public static com.google.common.collect.Range<ZonedDateTime> toDateTimeRange(LocalDate date, ZoneId zone)
date - 日期zone - 时区public static com.google.common.collect.Range<LocalDateTime> toDateTimeRange(com.google.common.collect.Range<LocalDate> dateRange)
dateRange - 日期范围public static com.google.common.collect.Range<ZonedDateTime> toDateTimeRange(com.google.common.collect.Range<LocalDate> dateRange, ZoneId zone)
dateRange - 日期范围public static boolean isLeapYear(int year)
year - 年份Copyright © 2026. All rights reserved.