public class TemporalUtil extends Object
Temporal
工具类封装Constructor and Description |
---|
TemporalUtil() |
Modifier and Type | Method and Description |
---|---|
static Duration |
between(Temporal startTimeInclude,
Temporal endTimeExclude)
获取两个日期的差,如果结束时间早于开始时间,获取结果为负。
|
static long |
between(Temporal startTimeInclude,
Temporal endTimeExclude,
ChronoUnit unit)
获取两个日期的差,如果结束时间早于开始时间,获取结果为负。
|
<T extends Temporal> |
offset(T temporal,
DayOfWeek dayOfWeek,
boolean isPrevious)
偏移到指定的周几
|
static <T extends Temporal> |
offset(T time,
long number,
TemporalUnit field)
日期偏移,根据field不同加不同值(偏移会修改传入的对象)
|
static ChronoUnit |
toChronoUnit(TimeUnit unit)
将
TimeUnit 转换为 ChronoUnit . |
static TimeUnit |
toTimeUnit(ChronoUnit unit)
转换
ChronoUnit 到 TimeUnit . |
public static Duration between(Temporal startTimeInclude, Temporal endTimeExclude)
返回结果为Duration
对象,通过调用toXXX方法返回相差单位
startTimeInclude
- 开始时间(包含)endTimeExclude
- 结束时间(不包含)Duration
对象public static long between(Temporal startTimeInclude, Temporal endTimeExclude, ChronoUnit unit)
返回结果为时间差的long值
startTimeInclude
- 开始时间(包括)endTimeExclude
- 结束时间(不包括)unit
- 时间差单位public static ChronoUnit toChronoUnit(TimeUnit unit) throws IllegalArgumentException
TimeUnit
转换为 ChronoUnit
.unit
- 被转换的TimeUnit
单位,如果为null
返回null
ChronoUnit
IllegalArgumentException
public static TimeUnit toTimeUnit(ChronoUnit unit) throws IllegalArgumentException
ChronoUnit
到 TimeUnit
.unit
- ChronoUnit
,如果为null
返回null
TimeUnit
IllegalArgumentException
- 如果TimeUnit
没有对应单位抛出public static <T extends Temporal> T offset(T time, long number, TemporalUnit field)
T
- 日期类型,如LocalDate或LocalDateTimetime
- Temporal
number
- 偏移量,正数为向后偏移,负数为向前偏移field
- 偏移单位,见ChronoUnit
,不能为nullCopyright © 2024. All rights reserved.