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 interface TemporalUnit
Known subtypesChronoUnit
A unit time is measured in.
ChronoUnit holds the units of the ISO
calendar.Methods
public abstract Duration getDuration() | The length of one unit; an estimate for the units a calendar decides. |
public abstract boolean isDurationEstimated() | Whether the length is an estimate. |
public abstract boolean isDateBased() | Whether this is a unit of a date: a day or longer. |
public abstract boolean isTimeBased() | Whether this is a unit of a time of day: shorter than a day. |
public default boolean isSupportedBy(Temporal temporal) | Whether temporal can add or subtract this unit. |
public abstract <R extends Temporal> R addTo(R temporal, long amount) | temporal moved by amount of this unit. |
public abstract long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive) | How many whole units lie between two values of the same kind. |
Method details
getDuration
public abstract Duration getDuration()The length of one unit; an estimate for the units a calendar decides.
isDurationEstimated
public abstract boolean isDurationEstimated()Whether the length is an estimate.
isDateBased
public abstract boolean isDateBased()Whether this is a unit of a date: a day or longer.
isTimeBased
public abstract boolean isTimeBased()Whether this is a unit of a time of day: shorter than a day.
isSupportedBy
public default 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 abstract <R extends Temporal> R addTo(R temporal, long amount)temporal moved by amount of this unit.between
public abstract long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)How many whole units lie between two values of the same kind.