TemporalUnit
java.time.TemporalUnit(时间单位)是一个接口,我们主要用它的实现类ChronoUnit,这是一个枚举,里面定义了常用的时间单位。
public enum ChronoUnit implements TemporalUnit {
// 纳秒
NANOS("Nanos", Duration.ofNanos(1)),
// 微秒
MICROS("Micros", Duration.ofNanos(1000)),
// 毫秒
MILLIS("Millis", Duration.ofNanos(1000_000)),
// 秒
SECONDS("Seconds", Duration.ofSeconds(1)),
// 分钟
MINUTES("Minutes", Duration.ofSeconds(60)),
// 小时
HOURS("Hours", Duration.ofSeconds(3600)),
// 半天
HALF_DAYS("HalfDays", Duration.ofSeconds(43200)),
// 天
DAYS("Days", Duration.ofSeconds(86400)),
// 周
WEEKS("Weeks", Duration.ofSeconds(7 * 86400L)),
// 月
MONTHS("Months", Duration.ofSeconds(31556952L / 12)),
// 年
YEARS("Years", Duration.ofSeconds(31556952L)),
// 十年
DECADES("Decades", Duration.ofSeconds(31556952L * 10L)),
// 世纪(即百年)
CENTURIES("Centuries", Duration.ofSeconds(31556952L * 100L)),
// 千年
MILLENNIA("Millennia", Duration.ofSeconds(31556952L * 1000L)),
// 十亿年
ERAS("Eras", Duration.ofSeconds(31556952L * 1000_000_000L)),
// 永远
FOREVER("Forever", Duration.ofSeconds(Long.MAX_VALUE, 999_999_999));
}
TemporalField
java.time.TemporalField(时间域)也是一个接口,表示时间字段,他的实现类为ChronoField,也是一个枚举
public enum ChronoField implements TemporalField {
NANO_OF_SECOND,
NANO_OF_DAY,
MICRO_OF_SECOND,
MICRO_OF_DAY,
MILLI_OF_SECOND,
MILLI_OF_DAY,
SECOND_OF_MINUTE,
SECOND_OF_DAY,
MINUTE_OF_HOUR,
MINUTE_OF_DAY,
HOUR_OF_AMPM,
CLOCK_HOUR_OF_AMPM,
HOUR_OF_DAY,
CLOCK_HOUR_OF_DAY,
AMPM_OF_DAY,
DAY_OF_WEEK,
ALIGNED_DAY_OF_WEEK_IN_MONTH,
ALIGNED_DAY_OF_WEEK_IN_YEAR,
DAY_OF_MONTH,
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
PROLEPTIC_MONTH,
YEAR_OF_ERA,
YEAR,
ERA,
INSTANT_SECONDS,
OFFSET_SECONDS;
}