Condividi tramite


TimeUnit.Convert Method

Definition

Overloads

Convert(Duration)

Converts the given time duration to this unit.

Convert(Int64, TimeUnit)

Converts the given time duration in the given unit to this unit.

Convert(Duration)

Converts the given time duration to this unit.

[Android.Runtime.Register("convert", "(Ljava/time/Duration;)J", "", ApiSince=33)]
public long Convert (Java.Time.Duration? duration);
[<Android.Runtime.Register("convert", "(Ljava/time/Duration;)J", "", ApiSince=33)>]
member this.Convert : Java.Time.Duration -> int64

Parameters

duration
Duration

the time duration

Returns

the converted duration in this unit, or Long.MIN_VALUE if conversion would negatively overflow, or Long.MAX_VALUE if it would positively overflow.

Attributes

Remarks

Converts the given time duration to this unit.

For any TimeUnit unit, unit.convert(Duration.ofNanos(n)) is equivalent to unit.convert(n, NANOSECONDS), and unit.convert(Duration.of(n, unit.toChronoUnit())) is equivalent to n (in the absence of overflow).

Added in 11.

Java documentation for java.util.concurrent.TimeUnit.convert(java.time.Duration).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Convert(Int64, TimeUnit)

Converts the given time duration in the given unit to this unit.

[Android.Runtime.Register("convert", "(JLjava/util/concurrent/TimeUnit;)J", "")]
public long Convert (long sourceDuration, Java.Util.Concurrent.TimeUnit? sourceUnit);
[<Android.Runtime.Register("convert", "(JLjava/util/concurrent/TimeUnit;)J", "")>]
member this.Convert : int64 * Java.Util.Concurrent.TimeUnit -> int64

Parameters

sourceDuration
Int64

the time duration in the given sourceUnit

sourceUnit
TimeUnit

the unit of the sourceDuration argument

Returns

the converted duration in this unit, or Long.MIN_VALUE if conversion would negatively overflow, or Long.MAX_VALUE if it would positively overflow.

Attributes

Remarks

Converts the given time duration in the given unit to this unit. Conversions from finer to coarser granularities truncate, so lose precision. For example, converting 999 milliseconds to seconds results in 0. Conversions from coarser to finer granularities with arguments that would numerically overflow saturate to Long.MIN_VALUE if negative or Long.MAX_VALUE if positive.

For example, to convert 10 minutes to milliseconds, use: TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)

Java documentation for java.util.concurrent.TimeUnit.convert(long, java.util.concurrent.TimeUnit).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to