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
- Object
- Enum<ChronoUnit>
- ChronoUnit
ImplementsComparable<ChronoUnit>, TemporalUnit
The units of the ISO calendar, with the JDK’s order, names and lengths.
Enum constants
NANOS | A nanosecond. |
MICROS | A microsecond. |
MILLIS | A millisecond. |
SECONDS | A second. |
MINUTES | A minute. |
HOURS | An hour. |
HALF_DAYS | Twelve hours. |
DAYS | A day. |
WEEKS | Seven days. |
MONTHS | A month, estimated as a twelfth of a year. |
YEARS | A year, estimated as 365.2425 days. |
DECADES | Ten years. |
CENTURIES | A hundred years. |
MILLENNIA | A thousand years. |
ERAS | An era, estimated as a billion years. |
FOREVER | Forever: 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
NANOSA nanosecond.
MICROS
MICROSA microsecond.
MILLIS
MILLISA millisecond.
SECONDS
SECONDSA second.
MINUTES
MINUTESA minute.
HOURS
HOURSAn hour.
HALF_DAYS
HALF_DAYSTwelve hours.
DAYS
DAYSA day.
WEEKS
WEEKSSeven days.
MONTHS
MONTHSA month, estimated as a twelfth of a year.
YEARS
YEARSA year, estimated as 365.2425 days.
DECADES
DECADESTen years.
CENTURIES
CENTURIESA hundred years.
MILLENNIA
MILLENNIAA thousand years.
ERAS
ERASAn era, estimated as a billion years.
FOREVER
FOREVERForever: 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())