Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package threeten
    Definition Classes
    org
  • package bp

    The main API for dates, times, instants, and durations.

    The main API for dates, times, instants, and durations.

    The classes defined here represent the principal date-time concepts, including instants, durations, dates, times, time-zones and periods. They are based on the ISO calendar system, which is the de facto world calendar following the proleptic Gregorian rules. All the classes are immutable and thread-safe.

    Each date time instance is composed of fields that are conveniently made available by the APIs. For lower level access to the fields refer to the org.threeten.bp.temporal package. Each class includes support for printing and parsing all manner of dates and times. Refer to the org.threeten.bp.format package for customization options.

    The org.threeten.bp.chrono package contains the calendar neutral API. This is intended for use by applications that need to use localized calendars. It is recommended that applications use the ISO-8601 dates and time classes from this package across system boundaries, such as to the database or across the network. The calendar neutral API should be reserved for interactions with users.

    Dates and Times

    org.threeten.bp.Instant is essentially a numeric timestamp. The current Instant can be retrieved from a org.threeten.bp.Clock. This is useful for logging and persistence of a point in time and has in the past been associated with storing the result from java.lang.System#currentTimeMillis().

    org.threeten.bp.LocalDate stores a date without a time. This stores a date like '2010-12-03' and could be used to store a birthday.

    org.threeten.bp.LocalTime stores a time without a date. This stores a time like '11:30' and could be used to store an opening or closing time.

    org.threeten.bp.LocalDateTime stores a date and time. This stores a date-time like '2010-12-03T11:30'.

    org.threeten.bp.OffsetTime stores a time and offset from UTC without a date. This stores a date like '11:30+01:00'. The ZoneOffset is of the form '+01:00'.

    org.threeten.bp.OffsetDateTime stores a date and time and offset from UTC. This stores a date-time like '2010-12-03T11:30+01:00'. This is sometimes found in XML messages and other forms of persistence, but contains less information than a full time-zone.

    org.threeten.bp.ZonedDateTime stores a date and time with a time-zone. This is useful if you want to perform accurate calculations of dates and times taking into account the org.threeten.bp.ZoneId, such as 'Europe/Paris'. Where possible, it is recommended to use a simpler class. The widespread use of time-zones tends to add considerable complexity to an application.

    Duration and Period

    Beyond dates and times, the API also allows the storage of period and durations of time. A org.threeten.bp.Duration is a simple measure of time along the time-line in nanoseconds. A org.threeten.bp.Period expresses an amount of time in units meaningful to humans, such as years or hours.

    Additional value types

    org.threeten.bp.Year stores a year on its own. This stores a single year in isolation, such as '2010'.

    org.threeten.bp.YearMonth stores a year and month without a day or time. This stores a year and month, such as '2010-12' and could be used for a credit card expiry.

    org.threeten.bp.MonthDay stores a month and day without a year or time. This stores a month and day-of-month, such as '--12-03' and could be used to store an annual event like a birthday without storing the year.

    org.threeten.bp.Month stores a month on its own. This stores a single month-of-year in isolation, such as 'DECEMBER'.

    org.threeten.bp.DayOfWeek stores a day-of-week on its own. This stores a single day-of-week in isolation, such as 'TUESDAY'.

    Definition Classes
    threeten
  • package chrono

    Support for calendar systems other than the default ISO.

    Support for calendar systems other than the default ISO.

    The main API is based around the calendar system defined in ISO-8601. This package provides support for alternate systems.

    The supported calendar systems includes:

    -Hijrah calendar -Japanese calendar -Minguo calendar -Thai Buddhist calendar

    It is intended that applications use the main API whenever possible, including code to read and write from a persistent data store, such as a database, and to send dates and times across a network. This package is then used at the user interface level to deal with localized input/output. See ChronoLocalDate for a full discussion of the issues.

    Example

    This example creates and uses a date in a non-ISO calendar system.

            // Print the Thai Buddhist date
            ChronoLocalDate now1 = ThaiBuddhistChronology.INSTANCE.now();
            int day = now1.get(ChronoField.DAY_OF_MONTH);
            int dow = now1.get(ChronoField.DAY_OF_WEEK);
            int month = now1.get(ChronoField.MONTH_OF_YEAR);
            int year = now1.get(ChronoField.YEAR);
            System.out.printf("  Today is %s %s %d-%s-%d%n", now1.getChronology().getId(),
                    dow, day, month, year);
    
            // Enumerate the list of available calendars and print today for each
            Set<String> names = Chronology.getAvailableIds();
            for (String name : names) {
                Chronology<?> chrono = Chronology.of(name);
                ChronoLocalDate<?> date = chrono.now();
                System.out.printf("   %20s: %s%n", chrono.getId(), date.toString());
            }
    
            // Print today's date and the last day of the year for the Thai Buddhist Calendar.
            ChronoLocalDate first = now1
                    .with(ChronoField.DAY_OF_MONTH, 1)
                    .with(ChronoField.MONTH_OF_YEAR, 1);
            ChronoLocalDate last = first
                    .plus(1, ChronoUnit.YEARS)
                    .minus(1, ChronoUnit.DAYS);
            System.out.printf("  %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(),
                    first, last);
    

    Definition Classes
    bp
  • package internal
    Definition Classes
    chrono
  • AbstractChronology
  • ChronoDateImpl
  • ChronoLocalDate
  • ChronoLocalDateTime
  • ChronoLocalDateTimeImpl
  • ChronoPeriod
  • ChronoPeriodImpl
  • ChronoZonedDateTime
  • ChronoZonedDateTimeImpl
  • Chronology
  • Era
  • HijrahChronology
  • HijrahDate
  • HijrahDateConfigurator
  • HijrahEra
  • IsoChronology
  • IsoEra
  • JapaneseChronology
  • JapaneseDate
  • JapaneseEra
  • MinguoChronology
  • MinguoDate
  • MinguoEra
  • Ser
  • ThaiBuddhistChronology
  • ThaiBuddhistDate
  • ThaiBuddhistEra

trait ChronoPeriod extends TemporalAmount

A date-based amount of time, such as '3 years, 4 months and 5 days' in an arbitrary chronology, intended for advanced globalization use cases.

This interface models a date-based amount of time in a calendar system. While most calendar systems use years, months and days, some do not. Therefore, this interface operates solely in terms of a set of supported units that are defined by the Chronology. The set of supported units is fixed for a given chronology. The amount of a supported unit may be set to zero.

The period is modeled as a directed amount of time, meaning that individual parts of the period may be negative.

Specification for implementors

This abstract class must be implemented with care to ensure other classes operate correctly. All implementations that can be instantiated must be final, immutable and thread-safe. Subclasses should be Serializable wherever possible.

Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ChronoPeriod
  2. TemporalAmount
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def addTo(temporal: Temporal): Temporal

    Adds this period to the specified temporal object.

    Adds this period to the specified temporal object.

    This returns a temporal object of the same observable type as the input with this period added.

    In most cases, it is clearer to reverse the calling pattern by using Temporal#plus(TemporalAmount).

    // these two lines are equivalent, but the second approach is recommended
    dateTime = thisPeriod.addTo(dateTime);
    dateTime = dateTime.plus(thisPeriod);
    

    The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units added.

    This instance is immutable and unaffected by this method call.

    temporal

    the temporal object to adjust, not null

    returns

    an object of the same type with the adjustment made, not null

    Definition Classes
    ChronoPeriodTemporalAmount
    Exceptions thrown

    ArithmeticException if numeric overflow occurs

    DateTimeException if unable to add

  2. abstract def get(unit: TemporalUnit): Long

    Gets the value of the requested unit.

    Gets the value of the requested unit.

    The supported units are chronology specific. They will typically be YEARS, MONTHS and DAYS. Requesting an unsupported unit will throw an exception.

    unit

    the { @code TemporalUnit} for which to return the value

    returns

    the long value of the unit

    Definition Classes
    ChronoPeriodTemporalAmount
    Exceptions thrown

    DateTimeException if the unit is not supported

    UnsupportedTemporalTypeException if the unit is not supported

  3. abstract def getChronology: Chronology

    Gets the chronology that defines the meaning of the supported units.

    Gets the chronology that defines the meaning of the supported units.

    The period is defined by the chronology. It controls the supported units and restricts addition/subtraction to ChronoLocalDate instances of the same chronology.

    returns

    the chronology defining the period, not null

  4. abstract def getUnits: List[TemporalUnit]

    Gets the set of units supported by this period.

    Gets the set of units supported by this period.

    The supported units are chronology specific. They will typically be YEARS, MONTHS and DAYS. They are returned in order from largest to smallest.

    This set can be used in conjunction with #get(TemporalUnit) to access the entire state of the period.

    returns

    a list containing the supported units, not null

    Definition Classes
    ChronoPeriodTemporalAmount
  5. abstract def minus(amountToSubtract: TemporalAmount): ChronoPeriod

    Returns a copy of this period with the specified period subtracted.

    Returns a copy of this period with the specified period subtracted.

    If the specified amount is a ChronoPeriod then it must have the same chronology as this period. Implementations may choose to accept or reject other TemporalAmount implementations.

    This instance is immutable and unaffected by this method call.

    amountToSubtract

    the period to subtract, not null

    returns

    a { @code ChronoPeriod} based on this period with the requested period subtracted, not null

    Exceptions thrown

    ArithmeticException if numeric overflow occurs

  6. abstract def multipliedBy(scalar: Int): ChronoPeriod

    Returns a new instance with each amount in this period in this period multiplied by the specified scalar.

    Returns a new instance with each amount in this period in this period multiplied by the specified scalar.

    This returns a period with each supported unit individually multiplied. For example, a period of "2 years, -3 months and 4 days" multiplied by 3 will return "6 years, -9 months and 12 days". No normalization is performed.

    scalar

    the scalar to multiply by, not null

    returns

    a { @code ChronoPeriod} based on this period with the amounts multiplied by the scalar, not null

    Exceptions thrown

    ArithmeticException if numeric overflow occurs

  7. abstract def normalized: ChronoPeriod

    Returns a copy of this period with the amounts of each unit normalized.

    Returns a copy of this period with the amounts of each unit normalized.

    The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, such that "15 months" would be normalized to "1 year and 3 months".

    This instance is immutable and unaffected by this method call.

    returns

    a { @code ChronoPeriod} based on this period with the amounts of each unit normalized, not null

    Exceptions thrown

    ArithmeticException if numeric overflow occurs

  8. abstract def plus(amountToAdd: TemporalAmount): ChronoPeriod

    Returns a copy of this period with the specified period added.

    Returns a copy of this period with the specified period added.

    If the specified amount is a ChronoPeriod then it must have the same chronology as this period. Implementations may choose to accept or reject other TemporalAmount implementations.

    This instance is immutable and unaffected by this method call.

    amountToAdd

    the period to add, not null

    returns

    a { @code ChronoPeriod} based on this period with the requested period added, not null

    Exceptions thrown

    ArithmeticException if numeric overflow occurs

  9. abstract def subtractFrom(temporal: Temporal): Temporal

    Subtracts this period from the specified temporal object.

    Subtracts this period from the specified temporal object.

    This returns a temporal object of the same observable type as the input with this period subtracted.

    In most cases, it is clearer to reverse the calling pattern by using Temporal#minus(TemporalAmount).

    // these two lines are equivalent, but the second approach is recommended
    dateTime = thisPeriod.subtractFrom(dateTime);
    dateTime = dateTime.minus(thisPeriod);
    

    The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units subtracted.

    This instance is immutable and unaffected by this method call.

    temporal

    the temporal object to adjust, not null

    returns

    an object of the same type with the adjustment made, not null

    Definition Classes
    ChronoPeriodTemporalAmount
    Exceptions thrown

    ArithmeticException if numeric overflow occurs

    DateTimeException if unable to subtract

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. def isNegative: Boolean

    Checks if any of the supported units of this period are negative.

    Checks if any of the supported units of this period are negative.

    returns

    true if any unit of this period is negative

  13. def isZero: Boolean

    Checks if all the supported units of this period are zero.

    Checks if all the supported units of this period are zero.

    returns

    true if this period is zero-length

  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def negated: ChronoPeriod

    Returns a new instance with each amount in this period negated.

    Returns a new instance with each amount in this period negated.

    This returns a period with each supported unit individually negated. For example, a period of "2 years, -3 months and 4 days" will be negated to "-2 years, 3 months and -4 days". No normalization is performed.

    returns

    a { @code ChronoPeriod} based on this period with the amounts negated, not null

    Exceptions thrown

    ArithmeticException if numeric overflow occurs, which only happens if one of the units has the value { @code Long.MIN_VALUE}

  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  19. def toString(): String
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from TemporalAmount

Inherited from AnyRef

Inherited from Any

Ungrouped