object Duration extends Serializable
- Alphabetic
- By Inheritance
- Duration
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
lazy val
ZERO: Duration
Constant for a duration of zero.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
between(startInclusive: Temporal, endExclusive: Temporal): Duration
Obtains an instance of
Duration
representing the duration between two instants.Obtains an instance of
Duration
representing the duration between two instants.Obtains a
Duration
representing the duration between two instants. This calculates the duration between two temporal objects of the same type. The difference in seconds is calculated usingTemporalUnit)
. The difference in nanoseconds is calculated using by querying theNANO_OF_SECOND
field.The result of this method can be a negative period if the end is before the start. To guarantee to obtain a positive duration call abs() on the result.
- startInclusive
the start instant, inclusive, not null
- endExclusive
the end instant, exclusive, not null
- returns
a { @code Duration}, not null
- Exceptions thrown
ArithmeticException
if the calculation exceeds the capacity of { @code Duration}DateTimeException
if the seconds between the temporals cannot be obtained
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
from(amount: TemporalAmount): Duration
Obtains an instance of
Duration
from an amount.Obtains an instance of
Duration
from an amount.This obtains a duration based on the specified amount. A TemporalAmount represents an amount of time, which may be date-based or time-based, which this factory extracts to a duration.
The conversion loops around the set of units from the amount and uses the duration of the unit to calculate the total Duration. Only a subset of units are accepted by this method. The unit must either have an exact duration or be ChronoUnit.DAYS which is treated as 24 hours. If any other units are found then an exception is thrown.
- amount
the amount to convert, not null
- returns
a { @code Duration}, not null
- Exceptions thrown
ArithmeticException
if a numeric overflow occursDateTimeException
if the amount cannot be converted
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
of(amount: Long, unit: TemporalUnit): Duration
Obtains an instance of
Duration
from a duration in the specified unit.Obtains an instance of
Duration
from a duration in the specified unit.The parameters represent the two parts of a phrase like '6 Hours'. For example:
Duration.of(3, SECONDS); Duration.of(465, HOURS);
Only a subset of units are accepted by this method. The unit must either have anexact duration
or beChronoUnit#DAYS
which is treated as 24 hours. Other units throw an exception.- amount
the amount of the duration, measured in terms of the unit, positive or negative
- unit
the unit that the duration is measured in, must have an exact duration, not null
- returns
a { @code Duration}, not null
- Exceptions thrown
ArithmeticException
if a numeric overflow occursDateTimeException
if the period unit has an estimated duration
-
def
ofDays(days: Long): Duration
Obtains an instance of
Duration
from a number of standard 24 hour days.Obtains an instance of
Duration
from a number of standard 24 hour days.The seconds are calculated based on the standard definition of a day, where each day is 86400 seconds which implies a 24 hour day. The nanosecond in second field is set to zero.
- days
the number of days, positive or negative
- returns
a { @code Duration}, not null
- Exceptions thrown
ArithmeticException
if the input days exceeds the capacity of { @code Duration}
-
def
ofHours(hours: Long): Duration
Obtains an instance of
Duration
from a number of standard length hours.Obtains an instance of
Duration
from a number of standard length hours.The seconds are calculated based on the standard definition of an hour, where each hour is 3600 seconds. The nanosecond in second field is set to zero.
- hours
the number of hours, positive or negative
- returns
a { @code Duration}, not null
- Exceptions thrown
ArithmeticException
if the input hours exceeds the capacity of { @code Duration}
-
def
ofMillis(millis: Long): Duration
Obtains an instance of
Duration
from a number of milliseconds.Obtains an instance of
Duration
from a number of milliseconds.The seconds and nanoseconds are extracted from the specified milliseconds.
- millis
the number of milliseconds, positive or negative
- returns
a { @code Duration}, not null
-
def
ofMinutes(minutes: Long): Duration
Obtains an instance of
Duration
from a number of standard length minutes.Obtains an instance of
Duration
from a number of standard length minutes.The seconds are calculated based on the standard definition of a minute, where each minute is 60 seconds. The nanosecond in second field is set to zero.
- minutes
the number of minutes, positive or negative
- returns
a { @code Duration}, not null
- Exceptions thrown
ArithmeticException
if the input minutes exceeds the capacity of { @code Duration}
-
def
ofNanos(nanos: Long): Duration
Obtains an instance of
Duration
from a number of nanoseconds.Obtains an instance of
Duration
from a number of nanoseconds.The seconds and nanoseconds are extracted from the specified nanoseconds.
- nanos
the number of nanoseconds, positive or negative
- returns
a { @code Duration}, not null
-
def
ofSeconds(seconds: Long, nanoAdjustment: Long): Duration
Obtains an instance of
Duration
from a number of seconds and an adjustment in nanoseconds.Obtains an instance of
Duration
from a number of seconds and an adjustment in nanoseconds.This method allows an arbitrary number of nanoseconds to be passed in. The factory will alter the values of the second and nanosecond in order to ensure that the stored nanosecond is in the range 0 to 999,999,999. For example, the following will result in the exactly the same duration:
Duration.ofSeconds(3, 1); Duration.ofSeconds(4, -999_999_999); Duration.ofSeconds(2, 1000_000_001);
- seconds
the number of seconds, positive or negative
- nanoAdjustment
the nanosecond adjustment to the number of seconds, positive or negative
- returns
a { @code Duration}, not null
- Exceptions thrown
ArithmeticException
if the adjustment causes the seconds to exceed the capacity of { @code Duration}
-
def
ofSeconds(seconds: Long): Duration
Obtains an instance of
Duration
from a number of seconds.Obtains an instance of
Duration
from a number of seconds.The nanosecond in second field is set to zero.
- seconds
the number of seconds, positive or negative
- returns
a { @code Duration}, not null
-
def
parse(text: CharSequence): Duration
Obtains a
Duration
from a text string such asPnDTnHnMn.nS
.Obtains a
Duration
from a text string such asPnDTnHnMn.nS
.This will parse a textual representation of a duration, including the string produced by
toString()
. The formats accepted are based on the ISO-8601 duration formatPnDTnHnMn.nS
with days considered to be exactly 24 hours.The string starts with an optional sign, denoted by the ASCII negative or positive symbol. If negative, the whole period is negated. The ASCII letter "P" is next in upper or lower case. There are then four sections, each consisting of a number and a suffix. The sections have suffixes in ASCII of "D", "H", "M" and "S" for days, hours, minutes and seconds, accepted in upper or lower case. The suffixes must occur in order. The ASCII letter "T" must occur before the first occurrence, if any, of an hour, minute or second section. At least one of the four sections must be present, and if "T" is present there must be at least one section after the "T". The number part of each section must consist of one or more ASCII digits. The number may be prefixed by the ASCII negative or positive symbol. The number of days, hours and minutes must parse to a
long
. The number of seconds must parse to along
with optional fraction. The decimal point may be either a dot or a comma. The fractional part may have from zero to 9 digits.The leading plus/minus sign, and negative values for other units are not part of the ISO-8601 standard.
Examples:
"PT20.345S" -> parses as "20.345 seconds" "PT15M" -> parses as "15 minutes" (where a minute is 60 seconds) "PT10H" -> parses as "10 hours" (where an hour is 3600 seconds) "P2D" -> parses as "2 days" (where a day is 24 hours or 86400 seconds) "P2DT3H4M" -> parses as "2 days, 3 hours and 4 minutes" "P-6H3M" -> parses as "-6 hours and +3 minutes" "-P6H3M" -> parses as "-6 hours and -3 minutes" "-P-6H+3M" -> parses as "+6 hours and -3 minutes"
- text
the text to parse, not null
- returns
the parsed duration, not null
- Exceptions thrown
DateTimeParseException
if the text cannot be parsed to a duration
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()