java.time.Period 类
在本教程中,您将学习如何使用java.time.Period类,简介java.time.Period类以年、月和日的形式对时间量或时间量进行建模。
java.time.Period 类以年、月和日的形式对时间量或时间量进行建模。
类声明
以下是 java.time.Period 类的声明 −
public final class Period extends Object implements ChronoPeriod, Serializable
运行实例 »
点击 "运行实例" 按钮查看在线实例
字段
以下是 Java.time.Period 类的字段 −
static Period ZERO − 周期为零的常量。
类方法
序号 | 方法 & 描述 |
---|---|
1 | Temporal addTo(Temporal temporal)
将此 Period 添加到指定的时间对象。 |
2 | static Period between(LocalDate startInclusive, LocalDate endExclusive)
获取由两个日期之间的年数、月数和天数组成的 Period。 |
3 | boolean equals(Object otherPeriod)
检查此期间是否等于指定的期间。 |
4 | static Duratio from(TemporalAmount amount)
从时间量中获取 Period 的实例。 |
5 | long get(TemporalUnit unit)
获取请求单位的值。 |
6 | IsoChronology getChronology()
获取这个时期的年表,也就是ISO日历系统。 |
7 | int getDays()
获取此期间的天数。 |
8 | int getMonths()
获取此期间的月数。 |
9 | List<TemporalUnit> getUnits()
获取此 Period 支持的单位集。 |
10 | int hashCode()
此期间的哈希码。 |
11 | boolean isNegative()
检查此 Period 是否为负数,不包括零。 |
12 | boolean isZero()
检查此期间的长度是否为零。 |
13 | Period minus(TemporalAmount amountToSubtract)
返回此 Period 的副本,减去指定的 Period。 |
14 | Period minusDays(long daysToSubtract)
返回此期间减去指定天数的副本。 |
15 | Period minusMonths(long months)
返回此期间减去指定月份的副本。 |
16 | Period minusYears(long years)
返回此期间减去指定年份的副本。 |
17 | Period multipliedBy(long multiplicand)
返回此 Period 的副本乘以标量。 |
18 | Period negated()
返回此 Period 的副本,长度取反。 |
19 | Period normalized()
返回此期间的副本,其中年份和月份标准化。 |
20 | static Period of(int years, int months, int days)
获取代表年、月和日数的 Period。 |
21 | static Period ofDays(int days)
获取表示天数的 Period。 |
22 | static Period ofMonths(int months)
获取表示月份数的 Period。 |
23 | static Period ofWeeks(int weeks)
获取表示周数的 Period。 |
24 | static Period ofYears(int years)
获取表示周数的 Period。 |
25 | static Period parse(CharSequence text)
从 PnYnMnD 等文本字符串中获取句点。 |
26 | Period plus(TemporalAmount amountToAdd)
返回此期间的副本,其中添加了指定的期间。 |
27 | Period plusDays(long daysToAdd)
返回此期间的副本,并添加指定的天数。 |
28 | Period plusMonths(long monthsToAdd)
返回此期间的副本,并添加指定的月份。 |
29 | Period plusYears(long yearsToAdd)
返回此期间的副本,并添加指定的年份。 |
30 | Temporal subtractFrom(Temporal temporal)
从指定的时间对象中减去此期间。 |
31 | String toString()
此 Period 的字符串表示,使用基于 ISO-8601 秒的表示,例如 PT8H6M12.345S。 |
32 | long toTotalMonths()
获取此期间的总月数。 |
33 | Period withDays(int days)
返回具有指定天数的此期间的副本。 |
34 | Period withMonths(int months)
返回具有指定月数的此期间的副本。 |
35 | Period withYears(int years)
返回具有指定年数的此期间的副本。 |
继承的方法
这个类继承了以下类的方法 −
- Java.lang.Object