Period (Java Platform SE 8 ) (original) (raw)


public final class Period
extends Object
implements ChronoPeriod, Serializable
A date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days'.
This class models a quantity or amount of time in terms of years, months and days. See Duration for the time-based equivalent to this class.
Durations and periods differ in their treatment of daylight savings time when added to ZonedDateTime. A Duration will add an exact number of seconds, thus a duration of one day is always exactly 24 hours. By contrast, a Period will add a conceptual day, trying to maintain the local time.
For example, consider adding a period of one day and a duration of one day to 18:00 on the evening before a daylight savings gap. The Period will add the conceptual day and result in a ZonedDateTime at 18:00 the following day. By contrast, the Duration will add exactly 24 hours, resulting in aZonedDateTime at 19:00 the following day (assuming a one hour DST gap).
The supported units of a period are YEARS,MONTHS and DAYS. All three fields are always present, but may be set to zero.
The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time.
The period is modeled as a directed amount of time, meaning that individual parts of the period may be negative.
This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances ofPeriod may have unpredictable results and should be avoided. The equals method should be used for comparisons.
Implementation Requirements:
This class is immutable and thread-safe.
Since:
1.8
See Also:
Serialized Form

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.