averageTime = (time1 + time2)/2, there will be overflow even with dates
beginning in 2004. Moreover, even if these problems don't occur, there is the issue of
conversion back and forth between different systems.
Binary datetimes differ in a number of ways: the datatype, the unit, and the epoch (origin). We refer to these as time scales.
ICU implements a universal time scale that is similar to the .NET framework's System.DateTime. The universal time scale is a 64-bit integer that holds ticks since midnight, January 1st, 0001. (One tick is 100 nanoseconds.) Negative values are supported. This has enough range to guarantee that calculations involving dates around the present are safe.
The universal time scale always measures time according to the proleptic Gregorian calendar. That is, the Gregorian calendar's leap year rules are used for all times, even before 1582 when it was introduced. (This is different from the default ICU calendar which switches from the Julian to the Gregorian calendar in 1582. See GregorianCalendar.setGregorianChange() and ucal_setGregorianChange().) ICU provides conversion functions to and from all other major time scales, allowing datetimes in any time scale to be converted to the universal time scale, safely manipulated, and converted back to any other datetime time scale.
For more details and background, see the Universal Time Scale chapter in the ICU User Guide.
| Modifier and Type | Class and Description |
|---|---|
| private static class | UniversalTimeScale.TimeScaleData
This class holds the data that describes a particular time scale. |
| Modifier and Type | Field and Description |
|---|---|
| private static final long | |
| public static final int | DB2_TIME
Used in DB2. |
| public static final int | DOTNET_DATE_TIME
Used in the .NET framework's |
| public static final int | EPOCH_OFFSET_MINUS_1_VALUE
The constant used to select the epoch offset minus one value for a time scale. |
| public static final int | EPOCH_OFFSET_PLUS_1_VALUE
The constant used to select the epoch plus one value for a time scale. |
| public static final int | EPOCH_OFFSET_VALUE
The constant used to select the epoch offset value for a time scale. |
| public static final int | EXCEL_TIME
Used in Excel. |
| public static final int | FROM_MAX_VALUE
The constant used to select the maximum from value for a time scale. |
| public static final int | FROM_MIN_VALUE
The constant used to select the minimum from value for a time scale. |
| private static final long | |
| public static final int | ICU4C_TIME
Used in the ICU4C. |
| public static final int | JAVA_TIME
Used in the JDK. |
| public static final int | MAC_OLD_TIME
Used in older Macintosh systems. |
| public static final int | MAC_TIME
Used in the JDK. |
| public static final int | MAX_ROUND_VALUE
The constant used to select the maximum safe rounding value for a time scale. |
| public static final int | MAX_SCALE
This is the first unused time scale value. |
| public static final int | MAX_SCALE_VALUE
The number of time scale values. |
| private static final long | |
| private static final long | |
| public static final int | MIN_ROUND_VALUE
The constant used to select the minimum safe rounding value for a time scale. |
| private static final long | |
| private static final long | |
| private static final long | |
| private static final UniversalTimeScale. | |
| public static final int | TO_MAX_VALUE
The constant used to select the maximum to value for a time scale. |
| public static final int | TO_MIN_VALUE
The constant used to select the minimum to value for a time scale. |
| public static final int | UNITS_ROUND_VALUE
The constant used to select the units round value for a time scale. |
| public static final int | UNITS_VALUE
The constant used to select the units value for a time scale. |
| public static final int | UNIX_MICROSECONDS_TIME
Data is a |
| public static final int | UNIX_TIME
Used in Unix systems. |
| public static final int | WINDOWS_FILE_TIME
Used in Windows for file times. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static BigDecimal | Returns: The datetime converted to the universal time scaleThe otherTime, int double datetimeThe time scale to convert from timeScale)Convert a |
| public static BigDecimal | Returns: The datetime converted to the universal time scaleThe otherTime, int long datetimeThe time scale to convert from timeScale)Convert a |
| public static BigDecimal | Returns: The datetime converted to the universal time scaleThe otherTime, int BigDecimal datetimeThe time scale to convert from timeScale)Convert a |
| public static long | Returns: The datetime converted to the universal time scaleThe otherTime, int long datetimeThe time scale to convert from timeScale)Convert a |
| private static UniversalTimeScale. | |
| private static UniversalTimeScale. | Returns: theTimeScaleData object for the given time scale- the time scale scale)Return the |
| public static long | Returns: - the value.- the time scale scale, int - a constant representing the value to get value)Get a value associated with a particular time scale. |
| public static BigDecimal | Returns: The datetime converted to the given time scaleThe datetime in the universal time scale universalTime, int The time scale to convert to timeScale)Convert a datetime from the universal time scale to a |
| public static BigDecimal | Returns: The datetime converted to the given time scaleThe datetime in the universal time scale universalTime, int The time scale to convert to timeScale)Convert a datetime from the universal time scale to a |
| public static BigDecimal | Returns: the time in the given time scalethe time in the Universal Time scale universalTime, int the time scale to convert to timeScale)
Deprecated
This API is ICU internal only.
Convert a time in the Universal Time Scale into another time
scale.
|
| public static long | Returns: The datetime converted to the given time scaleThe datetime in the universal time scale universalTime, int The time scale to convert to timeScale)Convert a datetime from the universal time scale stored as a |
| private static UniversalTimeScale. |
| days | back to summary |
|---|---|
| private static final long days | |
| DB2_TIME | back to summary |
|---|---|
| public static final int DB2_TIME Used in DB2. Data is a
| |
| DOTNET_DATE_TIME | back to summary |
|---|---|
| public static final int DOTNET_DATE_TIME Used in the .NET framework's
| |
| EPOCH_OFFSET_MINUS_1_VALUE | back to summary |
|---|---|
| public static final int EPOCH_OFFSET_MINUS_1_VALUE
Deprecated This API is ICU internal only. The constant used to select the epoch offset minus one value for a time scale. Note This is an internal value. DO NOT USE IT. May not actually be equal to the epoch offset value minus one.
| |
| EPOCH_OFFSET_PLUS_1_VALUE | back to summary |
|---|---|
| public static final int EPOCH_OFFSET_PLUS_1_VALUE The constant used to select the epoch plus one value for a time scale. Note This is an internal value. DO NOT USE IT. May not actually be equal to the epoch offset value plus one.
| |
| EPOCH_OFFSET_VALUE | back to summary |
|---|---|
| public static final int EPOCH_OFFSET_VALUE The constant used to select the epoch offset value for a time scale.
| |
| EXCEL_TIME | back to summary |
|---|---|
| public static final int EXCEL_TIME Used in Excel. Data is a
| |
| FROM_MAX_VALUE | back to summary |
|---|---|
| public static final int FROM_MAX_VALUE The constant used to select the maximum from value for a time scale.
| |
| FROM_MIN_VALUE | back to summary |
|---|---|
| public static final int FROM_MIN_VALUE The constant used to select the minimum from value for a time scale.
| |
| hours | back to summary |
|---|---|
| private static final long hours | |
| ICU4C_TIME | back to summary |
|---|---|
| public static final int ICU4C_TIME Used in the ICU4C. Data is a
| |
| JAVA_TIME | back to summary |
|---|---|
| public static final int JAVA_TIME Used in the JDK. Data is a
| |
| MAC_OLD_TIME | back to summary |
|---|---|
| public static final int MAC_OLD_TIME Used in older Macintosh systems. Data is an
| |
| MAC_TIME | back to summary |
|---|---|
| public static final int MAC_TIME Used in the JDK. Data is a
| |
| MAX_ROUND_VALUE | back to summary |
|---|---|
| public static final int MAX_ROUND_VALUE
Deprecated This API is ICU internal only. The constant used to select the maximum safe rounding value for a time scale. Note This is an internal value. DO NOT USE IT.
| |
| MAX_SCALE | back to summary |
|---|---|
| public static final int MAX_SCALE
Deprecated ICU 59 This is the first unused time scale value. | |
| MAX_SCALE_VALUE | back to summary |
|---|---|
| public static final int MAX_SCALE_VALUE
Deprecated This API is ICU internal only. The number of time scale values. Note This is an internal value. DO NOT USE IT.
| |
| microseconds | back to summary |
|---|---|
| private static final long microseconds | |
| milliseconds | back to summary |
|---|---|
| private static final long milliseconds | |
| MIN_ROUND_VALUE | back to summary |
|---|---|
| public static final int MIN_ROUND_VALUE
Deprecated This API is ICU internal only. The constant used to select the minimum safe rounding value for a time scale. Note This is an internal value. DO NOT USE IT.
| |
| minutes | back to summary |
|---|---|
| private static final long minutes | |
| seconds | back to summary |
|---|---|
| private static final long seconds | |
| ticks | back to summary |
|---|---|
| private static final long ticks | |
| timeScaleTable | back to summary |
|---|---|
| private static final UniversalTimeScale. | |
| TO_MAX_VALUE | back to summary |
|---|---|
| public static final int TO_MAX_VALUE The constant used to select the maximum to value for a time scale.
| |
| TO_MIN_VALUE | back to summary |
|---|---|
| public static final int TO_MIN_VALUE The constant used to select the minimum to value for a time scale.
| |
| UNITS_ROUND_VALUE | back to summary |
|---|---|
| public static final int UNITS_ROUND_VALUE
Deprecated This API is ICU internal only. The constant used to select the units round value for a time scale. Note This is an internal value. DO NOT USE IT.
| |
| UNITS_VALUE | back to summary |
|---|---|
| public static final int UNITS_VALUE The constant used to select the units value for a time scale.
| |
| UNIX_MICROSECONDS_TIME | back to summary |
|---|---|
| public static final int UNIX_MICROSECONDS_TIME Data is a
| |
| UNIX_TIME | back to summary |
|---|---|
| public static final int UNIX_TIME Used in Unix systems. Data is an
| |
| WINDOWS_FILE_TIME | back to summary |
|---|---|
| public static final int WINDOWS_FILE_TIME Used in Windows for file times. Data is a
| |
| UniversalTimeScale | back to summary |
|---|---|
| private UniversalTimeScale() | |
| bigDecimalFrom | back to summary |
|---|---|
| public static BigDecimal bigDecimalFrom(double otherTime, int timeScale) Convert a
| |
| bigDecimalFrom | back to summary |
|---|---|
| public static BigDecimal bigDecimalFrom(long otherTime, int timeScale) Convert a
| |
| bigDecimalFrom | back to summary |
|---|---|
| public static BigDecimal bigDecimalFrom(BigDecimal otherTime, int timeScale) Convert a
| |
| from | back to summary |
|---|---|
| public static long from(long otherTime, int timeScale) Convert a
| |
| fromRangeCheck | back to summary |
|---|---|
| private static UniversalTimeScale. | |
| getTimeScaleData | back to summary |
|---|---|
| private static UniversalTimeScale. Return the
| |
| getTimeScaleValue | back to summary |
|---|---|
| public static long getTimeScaleValue(int scale, int value) Get a value associated with a particular time scale.
| |
| toBigDecimal | back to summary |
|---|---|
| public static BigDecimal toBigDecimal(long universalTime, int timeScale) Convert a datetime from the universal time scale to a
| |
| toBigDecimal | back to summary |
|---|---|
| public static BigDecimal toBigDecimal(BigDecimal universalTime, int timeScale) Convert a datetime from the universal time scale to a
| |
| toBigDecimalTrunc | back to summary |
|---|---|
| public static BigDecimal toBigDecimalTrunc(BigDecimal universalTime, int timeScale)
Deprecated This API is ICU internal only. Convert a time in the Universal Time Scale into another time scale. The division used to do the conversion rounds down. Note This is an internal routine used by the tool that generates the to and from limits. Use it at your own risk.
| |
| toLong | back to summary |
|---|---|
| public static long toLong(long universalTime, int timeScale) Convert a datetime from the universal time scale stored as a
(i.e. we subtract units first to guarantee that we'll still be in range when we
add
For negative values to round away from zero, we need to flip the signs:
Since we also need to subtract the epochOffset, we fold the
| |
| toRangeCheck | back to summary |
|---|---|
| private static UniversalTimeScale. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long | |
| pack-priv long |
| Access | Constructor and Description |
|---|---|
| pack-priv | TimeScaleData(long theUnits, long theEpochOffset, long theToMin, long theToMax, long theFromMin, long theFromMax)
|
| epochOffset | back to summary |
|---|---|
| pack-priv long epochOffset | |
| epochOffsetM1 | back to summary |
|---|---|
| pack-priv long epochOffsetM1 | |
| epochOffsetP1 | back to summary |
|---|---|
| pack-priv long epochOffsetP1 | |
| fromMax | back to summary |
|---|---|
| pack-priv long fromMax | |
| fromMin | back to summary |
|---|---|
| pack-priv long fromMin | |
| maxRound | back to summary |
|---|---|
| pack-priv long maxRound | |
| minRound | back to summary |
|---|---|
| pack-priv long minRound | |
| toMax | back to summary |
|---|---|
| pack-priv long toMax | |
| toMin | back to summary |
|---|---|
| pack-priv long toMin | |
| units | back to summary |
|---|---|
| pack-priv long units | |
| unitsRound | back to summary |
|---|---|
| pack-priv long unitsRound | |
| TimeScaleData | back to summary |
|---|---|
| pack-priv TimeScaleData(long theUnits, long theEpochOffset, long theToMin, long theToMax, long theFromMin, long theFromMax) | |