This class models a quantity or amount of time in terms of seconds.
It is a type-safe way of representing a number of seconds in an application.
Note that Duration also models time in terms of seconds, but that
class allows nanoseconds, which this class does not.
The model is of a directed amount, meaning that the amount may be negative.
This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.
| Modifier and Type | Field and Description |
|---|---|
| private static final Pattern | PATTERN
The pattern for parsing. |
| private final int | seconds
The number of seconds. |
| private static final int | SECONDS_PER_DAY
The number of seconds per day. |
| private static final int | SECONDS_PER_HOUR
The number of seconds per hour. |
| private static final int | SECONDS_PER_MINUTE
The number of seconds per minute. |
| private static final long | serialVersionUID
A serialization identifier for this class. |
| public static final Seconds | ZERO
A constant for zero seconds. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Seconds | |
| public Temporal | Returns: an object of the same type with the adjustment made, not nullthe temporal object to adjust, not null temporal)Implements java. Adds this amount to the specified temporal object. |
| public static Seconds | |
| public int | Returns: the comparator value, negative if less, positive if greaterthe other amount, not null otherAmount)Implements java. Compares this amount to the specified |
| public Seconds | Returns: the amount divided by the specified divisor, not nullthe amount to divide by, may be negative divisor)Returns an instance with the amount divided by the specified divisor. |
| public boolean | Returns: true if the other amount is equal to this onethe other amount, null returns false otherAmount)Overrides java. Checks if this amount is equal to the specified |
| public static Seconds | Returns: the equivalent amount, not nullthe temporal amount to convert, not null amount)Obtains an instance of |
| public long | Returns: the long value of the unitthe unit)TemporalUnit for which to return the valueImplements java. Gets the value of the requested unit. |
| public int | |
| public List | Returns: a list containing the seconds unit, not nullImplements java. Gets the set of units supported by this amount. |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this amount. |
| public boolean | Returns: true if the amount is negative, false if the amount is zero or positiveChecks if the amount is negative. |
| public boolean | Returns: true if the amount is positive, false if the amount is zero or negativeChecks if the amount is positive. |
| public boolean | |
| public Seconds | Returns: aSeconds based on this instance with the requested amount subtracted, not nullthe amount to subtract, not null amountToSubtract)Returns a copy of this amount with the specified amount subtracted. |
| public Seconds | Returns: aSeconds based on this instance with the requested amount subtracted, not nullthe amount of seconds to add, may be negative seconds)Returns a copy of this amount with the specified number of seconds subtracted. |
| public Seconds | Returns: the amount multiplied by the specified scalar, not nullthe scalar to multiply by, not null scalar)Returns an instance with the amount multiplied by the specified scalar. |
| public Seconds | |
| public static Seconds | Returns: the number of seconds, not nullthe number of seconds, positive or negative seconds)Obtains a |
| public static Seconds | Returns: the amount with the input hours converted to seconds, not nullthe number of hours, positive or negative hours)Obtains a |
| public static Seconds | Returns: the amount with the input minutes converted to seconds, not nullthe number of minutes, positive or negative minutes)Obtains a |
| public static Seconds | Returns: the parsed period, not nullthe text to parse, not null text)Obtains a |
| public Seconds | Returns: aSeconds based on this instance with the requested amount added, not nullthe amount to add, not null amountToAdd)Returns a copy of this amount with the specified amount added. |
| public Seconds | Returns: aSeconds based on this instance with the requested amount added, not nullthe amount of seconds to add, may be negative seconds)Returns a copy of this amount with the specified number of seconds added. |
| private Object | |
| public Temporal | Returns: an object of the same type with the adjustment made, not nullthe temporal object to adjust, not null temporal)Implements java. Subtracts this amount from the specified temporal object. |
| public Duration | |
| public String | Returns: the number of seconds in ISO-8601 string formatOverrides java. Returns a string representation of the number of seconds. |
| PATTERN | back to summary |
|---|---|
| private static final Pattern PATTERN The pattern for parsing. | |
| seconds | back to summary |
|---|---|
| private final int seconds The number of seconds. | |
| SECONDS_PER_DAY | back to summary |
|---|---|
| private static final int SECONDS_PER_DAY The number of seconds per day. | |
| SECONDS_PER_HOUR | back to summary |
|---|---|
| private static final int SECONDS_PER_HOUR The number of seconds per hour. | |
| SECONDS_PER_MINUTE | back to summary |
|---|---|
| private static final int SECONDS_PER_MINUTE The number of seconds per minute. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID A serialization identifier for this class. | |
| ZERO | back to summary |
|---|---|
| public static final Seconds ZERO A constant for zero seconds. | |
| Seconds | back to summary |
|---|---|
| private Seconds(int seconds) Constructs an instance using a specific number of seconds.
| |
| abs | back to summary |
|---|---|
| public Seconds abs() Returns a copy of this duration with a positive length. This method returns a positive duration by effectively removing the sign from any negative total length. This instance is immutable and unaffected by this method call.
| |
| addTo | back to summary |
|---|---|
| public Temporal addTo(Temporal temporal) Implements java. Adds this amount to the specified temporal object. This returns a temporal object of the same observable type as the input with this amount added.
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended dateTime = thisAmount.addTo(dateTime); dateTime = dateTime.plus(thisAmount); Only non-zero amounts will be added. This instance is immutable and unaffected by this method call.
| |
| between | back to summary |
|---|---|
| public static Seconds between(Temporal startInclusive, Temporal endExclusive) Obtains a The start temporal is included, but the end temporal is not. The result of this method can be negative if the end is before the start. | |
| compareTo | back to summary |
|---|---|
| public int compareTo(Seconds otherAmount) Implements java. Compares this amount to the specified
The comparison is based on the total length of the amounts.
It is "consistent with equals", as defined by | |
| dividedBy | back to summary |
|---|---|
| public Seconds dividedBy(int divisor) Returns an instance with the amount divided by the specified divisor. The calculation uses integer division, thus 3 divided by 2 is 1. This instance is immutable and unaffected by this method call.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object otherAmount) Overrides java. Checks if this amount is equal to the specified The comparison is based on the total length of the durations. | |
| from | back to summary |
|---|---|
| public static Seconds from(TemporalAmount amount) Obtains an instance of
This obtains an instance based on the specified amount.
A
The result is calculated by looping around each unit in the specified amount.
Each amount is converted to seconds using
| |
| get | back to summary |
|---|---|
| public long get(TemporalUnit unit) Implements java. Gets the value of the requested unit.
This returns a value for the supported unit -
| |
| getAmount | back to summary |
|---|---|
| public int getAmount() Gets the number of seconds in this amount.
| |
| getUnits | back to summary |
|---|---|
| public List Implements java. Gets the set of units supported by this amount.
The single supported unit is
This set can be used in conjunction with
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this amount.
| |
| isNegative | back to summary |
|---|---|
| public boolean isNegative() Checks if the amount is negative.
| |
| isPositive | back to summary |
|---|---|
| public boolean isPositive() Checks if the amount is positive.
| |
| isZero | back to summary |
|---|---|
| public boolean isZero() Checks if the amount is zero.
| |
| minus | back to summary |
|---|---|
| public Seconds minus(TemporalAmount amountToSubtract) Returns a copy of this amount with the specified amount subtracted.
The parameter is converted using This instance is immutable and unaffected by this method call.
| |
| minus | back to summary |
|---|---|
| public Seconds minus(int seconds) Returns a copy of this amount with the specified number of seconds subtracted. This instance is immutable and unaffected by this method call.
| |
| multipliedBy | back to summary |
|---|---|
| public Seconds multipliedBy(int scalar) Returns an instance with the amount multiplied by the specified scalar. This instance is immutable and unaffected by this method call.
| |
| negated | back to summary |
|---|---|
| public Seconds negated() Returns an instance with the amount negated. This instance is immutable and unaffected by this method call.
| |
| of | back to summary |
|---|---|
| public static Seconds of(int seconds) Obtains a The resulting amount will have the specified seconds.
| |
| ofHours | back to summary |
|---|---|
| public static Seconds ofHours(int hours) Obtains a The resulting amount will be second-based, with the number of seconds equal to the number of hours multiplied by 3600.
| |
| ofMinutes | back to summary |
|---|---|
| public static Seconds ofMinutes(int minutes) Obtains a The resulting amount will be second-based, with the number of seconds equal to the number of minutes multiplied by 60.
| |
| parse | back to summary |
|---|---|
| public static Seconds parse(CharSequence text) Obtains a
This will parse the string produced by
The string starts with an optional sign, denoted by the ASCII negative
or positive symbol. If negative, the whole amount is negated.
The ASCII letter "P" is next in upper or lower case.
There are four sections consisting of a number and a suffix.
There is one section for days suffixed by "D",
followed by one section for hours suffixed by "H",
followed by one section for minutes suffixed by "M",
followed by one section for seconds suffixed by "S".
At least one section must be present.
If the hours, minutes or seconds section is present it must be prefixed by "T".
If the hours, minutes or seconds section is omitted the "T" must be omitted.
Letters must be in ASCII upper or lower case.
The number part of each section must consist of ASCII digits.
The number may be prefixed by the ASCII negative or positive symbol.
The number must parse to an The leading plus/minus sign, and negative values for days, hours, minutes and seconds are not part of the ISO-8601 standard. For example, the following are valid inputs: "PT2S" -- Seconds.of(2) "PT-2S" -- Seconds.of(-2) "-PT2S" -- Seconds.of(-2) "-PT-2S" -- Seconds.of(2) "PT3S" -- Seconds.of(3 * 60) "PT3H-2M7S" -- Seconds.of(3 * 3600 - 2 * 60 + 7) "P2D" -- Seconds.of(2 * 86400) "P2DT3H" -- Seconds.of(2 * 86400 + 3 * 3600)
| |
| plus | back to summary |
|---|---|
| public Seconds plus(TemporalAmount amountToAdd) Returns a copy of this amount with the specified amount added.
The parameter is converted using This instance is immutable and unaffected by this method call.
| |
| plus | back to summary |
|---|---|
| public Seconds plus(int seconds) Returns a copy of this amount with the specified number of seconds added. This instance is immutable and unaffected by this method call.
| |
| readResolve | back to summary |
|---|---|
| private Object readResolve() Resolves singletons.
| |
| subtractFrom | back to summary |
|---|---|
| public Temporal subtractFrom(Temporal temporal) Implements java. Subtracts this amount from the specified temporal object. This returns a temporal object of the same observable type as the input with this amount subtracted.
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended dateTime = thisAmount.subtractFrom(dateTime); dateTime = dateTime.minus(thisAmount); Only non-zero amounts will be subtracted. This instance is immutable and unaffected by this method call.
| |
| toDuration | back to summary |
|---|---|
| public Duration toDuration() Gets the number of seconds as a This returns a duration with the same number of seconds.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of the number of seconds. This will be in the format 'PTnS' where n is the number of seconds. | |