Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public enum ChronoUnit

  1. Object
  2. Enum<ChronoUnit>
  3. ChronoUnit

ImplementsComparable<ChronoUnit>, TemporalUnit

The units of the ISO calendar, with the JDK’s order, names and lengths.

Enum constants

NANOSA nanosecond.
MICROSA microsecond.
MILLISA millisecond.
SECONDSA second.
MINUTESA minute.
HOURSAn hour.
HALF_DAYSTwelve hours.
DAYSA day.
WEEKSSeven days.
MONTHSA month, estimated as a twelfth of a year.
YEARSA year, estimated as 365.2425 days.
DECADESTen years.
CENTURIESA hundred years.
MILLENNIAA thousand years.
ERASAn era, estimated as a billion years.
FOREVERForever: longer than any other unit.

Methods

public static ChronoUnit[] values()
public static ChronoUnit valueOf(String name)
public Duration getDuration()The length of one unit; an estimate for the units a calendar decides.
public boolean isDurationEstimated()Whether the length is an estimate.
public boolean isDateBased()Whether this is a unit of a date: a day or longer.
public boolean isTimeBased()Whether this is a unit of a time of day: shorter than a day.
public boolean isSupportedBy(Temporal temporal)Whether temporal can add or subtract this unit.
public <R extends Temporal> R addTo(R temporal, long amount)temporal moved by amount of this unit.
public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)How many whole units lie between two values of the same kind.
public String toString()Returns a string representation of the object.

Inherited methods

Enum constant details

NANOS

NANOS
A nanosecond.

MICROS

MICROS
A microsecond.

MILLIS

MILLIS
A millisecond.

SECONDS

SECONDS
A second.

MINUTES

MINUTES
A minute.

HOURS

HOURS
An hour.

HALF_DAYS

HALF_DAYS
Twelve hours.

DAYS

DAYS
A day.

WEEKS

WEEKS
Seven days.

MONTHS

MONTHS
A month, estimated as a twelfth of a year.

YEARS

YEARS
A year, estimated as 365.2425 days.

DECADES

DECADES
Ten years.

CENTURIES

CENTURIES
A hundred years.

MILLENNIA

MILLENNIA
A thousand years.

ERAS

ERAS
An era, estimated as a billion years.

FOREVER

FOREVER
Forever: longer than any other unit.

Method details

values

public static ChronoUnit[] values()

valueOf

public static ChronoUnit valueOf(String name)

getDuration

public Duration getDuration()
The length of one unit; an estimate for the units a calendar decides.

isDurationEstimated

public boolean isDurationEstimated()
Whether the length is an estimate.

isDateBased

public boolean isDateBased()
Whether this is a unit of a date: a day or longer.

isTimeBased

public boolean isTimeBased()
Whether this is a unit of a time of day: shorter than a day.

isSupportedBy

public boolean isSupportedBy(Temporal temporal)

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.

addTo

public <R extends Temporal> R addTo(R temporal, long amount)
temporal moved by amount of this unit.

between

public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)
How many whole units lie between two values of the same kind.

toString

public String toString()
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())