介绍
- java.time.Period
- public final class Period implements ChronoPeriod, Serializable
- 基于日期的时间量
- 两个
LocalDate
之间的时长是Period
Period
是一个基于日期的TemporalAmount
实现,存储年月日。Duration
是基于时间的TemporalAmount
实现,存储秒和纳秒,但使用其他基于Duration
的单位(例如分钟、小时和固定的 24 小时制日)提供一些访问
- 实现
TemporalAmount
, 可以获取的时间单位:- YEARS
- MONTHS
- DAYS
- 内部存储是
private final int years;
private final int months;
private final int days;
API
常量
- ZERO : P0D
static
-
ofYears
-
ofMonths
-
ofWeeks
-
ofDays
-
of
-
from
Period from(TemporalAmount amount)
-
between
Period between(LocalDate startDateInclusive, LocalDate endDateExclusive)
-
parse
- 反
toString
- 格式:
P6Y3M1D
表示 9年3月1天
- 反
public
- toTotalMonths
- 总月数
- toString
get
- getYears
- getMonths
- getDays
with
- withYears
- withMonths
- withDays
plus
- plusYears
- plusMonths
- plusDays
- minusYears
- minusMonths
- minusDays
- 20230630 Period java time20230630 period java time localtime 20230630 java time zoneddatetime 20230630 java time zoneoffset 20230630 java time localdatetime 20230630 java time 20230630 zoneid java time chronounit 20230630 temporal java datetimeformatter 20230630 format java 20230630 locale java util temporaladjusters 20230630 temporal java