Enum ChronoUnit

java.lang.Object
java.lang.Enum<ChronoUnit>
java.time.temporal.ChronoUnit
All Implemented Interfaces:
Comparable<ChronoUnit>, TemporalUnit

public enum ChronoUnit extends Enum<ChronoUnit> implements TemporalUnit
The units of the ISO calendar, with the JDK's order, names and lengths.
  • Enum Constant Details

    • NANOS

      public static final ChronoUnit NANOS
      A nanosecond.
    • MICROS

      public static final ChronoUnit MICROS
      A microsecond.
    • MILLIS

      public static final ChronoUnit MILLIS
      A millisecond.
    • SECONDS

      public static final ChronoUnit SECONDS
      A second.
    • MINUTES

      public static final ChronoUnit MINUTES
      A minute.
    • HOURS

      public static final ChronoUnit HOURS
      An hour.
    • HALF_DAYS

      public static final ChronoUnit HALF_DAYS
      Twelve hours.
    • DAYS

      public static final ChronoUnit DAYS
      A day.
    • WEEKS

      public static final ChronoUnit WEEKS
      Seven days.
    • MONTHS

      public static final ChronoUnit MONTHS
      A month, estimated as a twelfth of a year.
    • YEARS

      public static final ChronoUnit YEARS
      A year, estimated as 365.2425 days.
    • DECADES

      public static final ChronoUnit DECADES
      Ten years.
    • CENTURIES

      public static final ChronoUnit CENTURIES
      A hundred years.
    • MILLENNIA

      public static final ChronoUnit MILLENNIA
      A thousand years.
    • ERAS

      public static final ChronoUnit ERAS
      An era, estimated as a billion years.
    • FOREVER

      public static final ChronoUnit FOREVER
      Forever: longer than any other unit.
  • Method Details

    • values

      public static ChronoUnit[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static ChronoUnit valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • getDuration

      public Duration getDuration()
      Description copied from interface: TemporalUnit
      The length of one unit; an estimate for the units a calendar decides.
      Specified by:
      getDuration in interface TemporalUnit
    • isDurationEstimated

      public boolean isDurationEstimated()
      Description copied from interface: TemporalUnit
      Whether the length is an estimate.
      Specified by:
      isDurationEstimated in interface TemporalUnit
    • isDateBased

      public boolean isDateBased()
      Description copied from interface: TemporalUnit
      Whether this is a unit of a date: a day or longer.
      Specified by:
      isDateBased in interface TemporalUnit
    • isTimeBased

      public boolean isTimeBased()
      Description copied from interface: TemporalUnit
      Whether this is a unit of a time of day: shorter than a day.
      Specified by:
      isTimeBased in interface TemporalUnit
    • isSupportedBy

      public boolean isSupportedBy(Temporal temporal)
      Description copied from interface: TemporalUnit

      Whether temporal can add or subtract this unit.

      Answered by the unit's kind for the built-in temporals and otherwise by trying to add one, as the JDK's default does. It never asks temporal.isSupported(this): that is what calls here, so a custom unit relying on this default would recurse.

      Specified by:
      isSupportedBy in interface TemporalUnit
    • addTo

      public <R extends Temporal> R addTo(R temporal, long amount)
      Description copied from interface: TemporalUnit
      temporal moved by amount of this unit.
      Specified by:
      addTo in interface TemporalUnit
    • between

      public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)
      Description copied from interface: TemporalUnit
      How many whole units lie between two values of the same kind.
      Specified by:
      between in interface TemporalUnit
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Enum<ChronoUnit>