UniversalTimeScale.ToLong(Int64, UniversalTimeScaleType) Method

Definition

Convert a datetime from the universal time scale stored as a BigDecimal to a long in the given time scale.

[Android.Runtime.Register("toLong", "(JI)J", "", ApiSince=26)]
public static long ToLong (long universalTime, Android.Icu.Util.UniversalTimeScaleType timeScale);
[<Android.Runtime.Register("toLong", "(JI)J", "", ApiSince=26)>]
static member ToLong : int64 * Android.Icu.Util.UniversalTimeScaleType -> int64

Parameters

universalTime
Int64

The datetime in the universal time scale

timeScale
UniversalTimeScaleType

The time scale to convert to

Returns

The datetime converted to the given time scale

Attributes

Remarks

Convert a datetime from the universal time scale stored as a BigDecimal to a long in the given time scale.

Since this calculation requires a divide, we must round. The straight forward way to round by adding half of the divisor will push the sum out of range for values within have the divisor of the limits of the precision of a long. To get around this, we do the rounding like this:

(universalTime - units + units/2) / units + 1

(i.e. we subtract units first to guarantee that we'll still be in range when we add units/2. We then need to add one to the quotent to make up for the extra subtraction. This simplifies to:

(universalTime - units/2) / units - 1

For negative values to round away from zero, we need to flip the signs:

(universalTime + units/2) / units + 1

Since we also need to subtract the epochOffset, we fold the +/- 1 into the offset value. (i.e. epochOffsetP1, epochOffsetM1.)

Java documentation for android.icu.util.UniversalTimeScale.toLong(long, int).

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