Timestamps preserve precision, meaning the fields that are included, and the significant digits of any fractional second. Only common break points in the values are supported. Any unspecified fields are handled as the start of the new year/month/day.
IonValue classes, the equals methods on this class
perform a strict equivalence that observes the precision and local offset
of each timestamp.
This means that it's possible to have two Timestamp instances that
represent the same point in time but are not equals.
On the other hand, the compareTo methods perform point in time
comparison, ignoring precision and local offset.
Thus the natural comparison method of this class is not
consistent with equals. See the documentation of Comparable for
further discussion.
To illustrate this distinction, consider the following timestamps. None are
equals to each other, but any pair will return a zero result from
compareTo.
2009T2009-01T2009-01-01T2009-01-01T00:00Z2009-01-01T00:00:00Z2009-01-01T00:00:00.0Z2009-01-01T00:00:00.00Z2009-01-01T00:00:00.000Z etc.equals(Timestamp), compareTo(Timestamp)
| Modifier and Type | Class and Description |
|---|---|
| public static enum | Timestamp.
The precision of the Timestamp. |
| Modifier and Type | Field and Description |
|---|---|
| private byte | |
| private BigDecimal | |
| private byte | |
| private byte | |
| private byte | |
| private Integer | _offset
Minutes offset from UTC; zero means UTC proper,
|
| private Timestamp. | _precision
The precision of the Timestamp. |
| private byte | |
| private short | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| private static final boolean | |
| public static final int | DEFAULT_MAXIMUM_DIGITS_TEXT
The default maximum number of digits in the fractional component that will be written when a text representation of a timestamp is requested. |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int[] | |
| pack-priv static final int | |
| pack-priv static final BigDecimal | MAXIMUM_ALLOWED_TIMESTAMP_IN_MILLIS_DECIMAL
10000T in millis, upper bound exclusive. |
| pack-priv static final long | MAXIMUM_TIMESTAMP_IN_EPOCH_SECONDS
10000T in epoch seconds, upper bound exclusive. |
| pack-priv static final long | MAXIMUM_TIMESTAMP_IN_MILLIS
10000T in millis, upper bound exclusive. |
| pack-priv static final long | MINIMUM_TIMESTAMP_IN_EPOCH_SECONDS
0001-01-01T00:00:00.0Z epoch seconds. |
| pack-priv static final long | MINIMUM_TIMESTAMP_IN_MILLIS
0001-01-01T00:00:00.0Z in millis. |
| pack-priv static final BigDecimal | MINIMUM_TIMESTAMP_IN_MILLIS_DECIMAL
0001-01-01T00:00:00.0Z in millis. |
| private static final int | |
| private static final BigDecimal | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int[] | |
| pack-priv static final String | |
| public static final Integer | UNKNOWN_OFFSET
Unknown local offset from UTC. |
| public static final Integer | UTC_OFFSET
Local offset of zero hours from UTC. |
| Access | Constructor and Description |
|---|---|
| private | |
| private | Timestamp(int zyear, int zmonth)
Creates a new Timestamp, precise to the month, with unknown local offset. |
| public | Timestamp(int zyear, int zmonth, int zday)
Deprecated
Use
forDay(int, int, int) instead.
Creates a new Timestamp, precise to the day, with unknown local offset. |
| public | Timestamp(int year, int month, int day, int hour, int minute, Integer
the local offset from UTC, measured in minutes;
may be offset)null to represent an unknown local offset
Deprecated
Use
forMinute(int, int, int, int, int, Integer) instead.
Creates a new Timestamp, precise to the minute, with a given local offset. |
| public | Timestamp(int year, int month, int day, int hour, int minute, int second, Integer
the local offset from UTC, measured in minutes;
may be offset)null to represent an unknown local offset.
Deprecated
Use
forSecond(int, int, int, int, int, int, Integer) instead.
Creates a new Timestamp, precise to the second, with a given local offset. |
| public | Timestamp(int year, int month, int day, int hour, int minute, int second, BigDecimal
the fractional seconds; must not be frac, Integer null; if negative,
its absolute value is usedthe local offset from UTC, measured in minutes;
may be offset)null to represent an unknown local offset
Deprecated
Use
forSecond(int, int, int, int, int, BigDecimal, Integer)
instead.
Creates a new Timestamp, precise to the second or fractional second, with a given local offset. |
| private | Timestamp(Timestamp.
must be >= 0 and < 1 frac, Integer the local offset from UTC, measured in minutes;
may be offset, boolean shouldApplyOffset, boolean shouldCheckFraction)null to represent an unknown local offsetCreates a new Timestamp from the individual time components. |
| public | Timestamp(Calendar cal)
Deprecated
Use
forCalendar(Calendar) instead.
Creates a new Timestamp from a |
| private | |
| private | |
| public | Timestamp(BigDecimal
number of milliseconds (including any fractional
milliseconds) from the epoch (1970-01-01T00:00:00.000Z);
must not be millis, Integer nullthe local offset from UTC, measured in minutes;
may be localOffset)null to represent an unknown local offset
Deprecated
Use
forMillis(BigDecimal, Integer) instead.
Creates a new Timestamp that represents the point in time that is
|
| public | Timestamp(long
number of milliseconds from the epoch (1970-01-01T00:00:00.000Z) millis, Integer the local offset from UTC, measured in minutes;
may be localOffset)null to represent an unknown local offset.
Deprecated
Use
forMillis(long, Integer) instead.
Creates a new Timestamp that represents the point in time that is
|
| Modifier and Type | Method and Description |
|---|---|
| public final Timestamp | addDay(int
a number of days. amount)Returns a timestamp relative to this one by the given number of days. |
| public final Timestamp | addHour(int
a number of hours. amount)Returns a timestamp relative to this one by the given number of hours. |
| public final Timestamp | addMillis(long
a number of milliseconds. amount)Returns a timestamp relative to this one by the given number of milliseconds. |
| private Timestamp | Returns: a new Timestamp.the number of milliseconds to add. amount, Timestamp.the precision that the Timestamp will be extended to, if it does not already include that
precision. precision,true if and only if the `amount` includes milliseconds precision. If true, the
resulting timestamp's fraction will have precision at least to the millisecond. millisecondsPrecision)Adds the given number of milliseconds, extending (if necessary) the resulting Timestamp to the given precision. |
| public final Timestamp | addMinute(int
a number of minutes. amount)Returns a timestamp relative to this one by the given number of minutes. |
| public final Timestamp | addMonth(int
a number of months. amount)Returns a timestamp relative to this one by the given number of months. |
| private Timestamp | Returns: a new Timestamp.the number of months to add. amount, Timestamp.the precision that the Timestamp will be extended to, if it does not already include that
precision. precisionAdds the given number of months, extending (if necessary) the resulting Timestamp to the given precision. |
| public final Timestamp | addSecond(int
a number of seconds. amount)Returns a timestamp relative to this one by the given number of seconds. |
| public final Timestamp | addYear(int
a number of years. amount)Returns a timestamp relative to this one by the given number of years. |
| public final Timestamp | adjustDay(int
a number of days. amount)Returns a timestamp relative to this one by the given number of days. |
| public final Timestamp | adjustHour(int
a number of hours. amount)Returns a timestamp relative to this one by the given number of hours. |
| public final Timestamp | adjustMillis(long
a number of milliseconds. amount)Returns a timestamp relative to this one by the given number of milliseconds. |
| public final Timestamp | adjustMinute(int
a number of minutes. amount)Returns a timestamp relative to this one by the given number of minutes. |
| public final Timestamp | adjustMonth(int
a number of months. amount)Returns a timestamp relative to this one by the given number of months. |
| public final Timestamp | adjustSecond(int
a number of seconds. amount)Returns a timestamp relative to this one by the given number of seconds. |
| public final Timestamp | adjustYear(int
a number of years. amount)Returns a timestamp relative to this one by the given number of years. |
| private void | apply_offset(int
the local offset, in minutes from UTC. offset)Applies the local time zone offset from UTC to the applicable time field values. |
| public Calendar | Returns: a newCalendar instance, in its local time.Converts the value of this Timestamp as a |
| private static byte | |
| private static byte | |
| private static byte | |
| private static byte | |
| private static byte | |
| private static short | |
| private static Timestamp. | |
| private void | |
| public Timestamp | |
| public int | Returns: -1, 0, or 1 if thisTimestamp
is less than, equal to, or greater than t respectivelythe other t)Timestamp to compare this Timestamp toImplements java. Performs a comparison of the two points in time represented by two Timestamps. |
| public static Timestamp | createFromUtcFields(Timestamp.
the desired timestamp precision. The result may have a
different precision if the input data isn't precise enough. p,the local offset from UTC, measured in minutes;
may be offset)null to represent an unknown local offset.
Deprecated
Creates a new Timestamp from the individual time components. |
| public Date | |
| public boolean | equals(Object
the reference object with which to compare. t)Overrides java. Compares this |
| public boolean | |
| private static IllegalArgumentException | |
| private static IllegalArgumentException | |
| private BigDecimal | |
| public static Timestamp | Returns: a Timestamp instance, with precision determined by the smallest field set in theCalendar;
or null if calendar is nullConverts a |
| public static Timestamp | |
| public static Timestamp | forDay(int yearZ, int monthZ, int dayZ)
Returns a Timestamp, precise to the day, with unknown local offset. |
| public static Timestamp | forEpochSecond(long
The number of seconds from the unix epoch (1970-01-01T00:00:00.000Z) UTC. seconds, int The number of nanoseconds for the fractional component. Must be between 0 and 999,999,999. nanoOffset, Integer the local offset from UTC, measured in minutes;
may be localOffset)null to represent an unknown local offset.Returns a Timestamp that represents the point in time that is |
| public static Timestamp | forMillis(long
the number of milliseconds from the epoch (1970-01-01T00:00:00.000Z) in UTC. millis, Integer the local offset from UTC, measured in minutes;
may be localOffset)null to represent an unknown local offset.Returns a Timestamp that represents the point in time that is |
| public static Timestamp | forMillis(BigDecimal
number of milliseconds (including any fractional
milliseconds) from the epoch (1970-01-01T00:00:00.000Z);
must not be millis, Integer nullthe local offset from UTC, measured in minutes;
may be localOffset)null to represent an unknown local offsetThe same as |
| public static Timestamp | |
| public static Timestamp | forMonth(int yearZ, int monthZ)
Returns a Timestamp, precise to the month, with unknown local offset. |
| public static Timestamp | |
| public static Timestamp | forSecond(int year, int month, int day, int hour, int minute, BigDecimal
must be at least zero and less than 60. Must not be null. second, Integer the local offset from UTC, measured in minutes;
may be offset)null to represent an unknown local offsetReturns a Timestamp, precise to the second, with a given local offset. |
| public static Timestamp | Returns: a new Timestamp instance, in UTC, precise to the nanosecondnull if sqlTimestamp is nullassumed to have nanoseconds precision sqlTimestampConverts a |
| public static Timestamp | |
| public int | Returns: a number within the range [1, 31], in its local time; 1 is returned if the Timestamp isn't precise to the dayReturns the day (within the month) of this Timestamp, in its local time. |
| public BigDecimal | Returns: number of milliseconds (including any fractional milliseconds) from the epoch (1970-01-01T00:00:00.000Z)Returns a BigDecimal representing the Timestamp's point in time that is the number of milliseconds (including any fractional milliseconds) from the epoch. |
| public BigDecimal | Returns: a number within the range [0, 60); 0 is returned if the Timestamp isn't precise to the secondReturns the seconds of this Timestamp. |
| public BigDecimal | Returns: a BigDecimal within the range [0, 1);null is returned if the Timestamp isn't
precise to the fractional second
Deprecated
Returns the fractional second of this Timestamp. |
| public int | Returns: a number within the range [0, 23], in its local time; 0 is returned if the Timestamp isn't precise to the hourReturns the hour of this Timestamp, in its local time. |
| public Integer | Returns: null if the local offset is unknown
(i.e. -00:00)Returns the offset of this Timestamp, measured in minutes, for the local timezone in UTC. |
| public long | Returns: number of milliseconds (ignoring any fractional milliseconds) from the epoch (1970-01-01T00:00:00.000Z)Returns a number representing the Timestamp's point in time that is the number of milliseconds (ignoring any fractional milliseconds) from the epoch. |
| public int | Returns: a number within the range [0, 59], in its local time; 0 is returned if the Timestamp isn't precise to the minuteReturns the minute of this Timestamp, in its local time. |
| public int | Returns: a number within the range [1, 12], whereby 1 refers to January and 12 refers to December, in its local time; 1 is returned if the Timestamp isn't precise to the monthReturns the month of this Timestamp, in its local time. |
| public Timestamp. | |
| public int | Returns: a number within the range [0, 59]; 0 is returned if the Timestamp isn't precise to the secondReturns the seconds of this Timestamp, truncated to an integer. |
| public int | Returns: a number within the range [1, 9999], in its local timeReturns the year of this Timestamp, in its local time. |
| public int | Returns: a number within the range [1, 31], in UTC; 1 is returned if the Timestamp isn't precise to the dayReturns the day of this Timestamp, in UTC. |
| public BigDecimal | Returns: a number within the range [0, 60); 0 is returned if the Timestamp isn't precise to the secondReturns the seconds of this Timestamp. |
| public BigDecimal | Returns: a BigDecimal within the range [0, 1);null is returned if the Timestamp isn't
precise to the fractional second
Deprecated
Use
getZDecimalSecond() instead.
Returns the fractional second of this Timestamp. |
| public int | Returns: a number within the range [0, 23], in UTC; 0 is returned if the Timestamp isn't precise to the hourReturns the hour of this Timestamp, in UTC. |
| public int | Returns: a number within the range [0, 59], in UTC; 0 is returned if the Timestamp isn't precise to the minuteReturns the minute of this Timestamp, in UTC. |
| public int | Returns: a number within the range [1, 12], whereby 1 refers to January and 12 refers to December, in UTC; 1 is returned if the Timestamp isn't precise to the monthReturns the month of this Timestamp, in UTC. |
| public int | Returns: a number within the range [0, 59]; 0 is returned if the Timestamp isn't precise to the secondReturns the second of this Timestamp. |
| public int | Returns: a number within the range [1, 9999], in UTCReturns the year of this Timestamp, in UTC. |
| public int | |
| private boolean | |
| private static boolean | |
| private static byte | |
| private Timestamp | Returns: a new Timestamp in its local timeApplies the local offset from UTC to each of the applicable time field values and returns the new Timestamp. |
| public static Timestamp | Returns: a new Timestamp instance representing the current time.Returns a Timestamp representing the current time (based on the JVM clock), with an unknown local offset. |
| public static Timestamp | Returns: a new Timestamp instance, in UTC, representing the current time.Returns a Timestamp in UTC representing the current time (based on the the JVM clock). |
| public void | print(Appendable
not out)nullPrints to an |
| private void | print(Appendable
not out, int maximumDigits)nullPrints to an |
| private static void | print(Appendable
destination for the text image of the value out, Timestamp the time value with the fields adjusted to match the desired text output adjusted, int the maximum number of digits allowed in the fractional seconds maximumDigits)helper for print(out) and printZ(out) so that printZ can create a zulu time and pass it directly and print can apply the local offset and adjust the various fields (without breaking the contract to be immutable). |
| private static void | |
| private static void | |
| public void | printZ(Appendable
not out)nullPrints to an |
| private static int | |
| private static byte | |
| private static void | requirePrecisionWithinLimit(Timestamp
a Timestamp with a non-null fraction. value, int the maximum number of digits allowed. maximumDigits)Throws if the text representation of the timestamp would require more than the given number of digits in its fractional component. |
| private static short | |
| private void | set_fields_from_calendar(Calendar
must have at least one field set. cal, Timestamp.Copies data from a |
| private void | set_fields_from_millis(long millis)
This method uses deprecated methods from |
| private static void | |
| public String | toString()
Overrides java. Returns the string representation (in Ion format) of this Timestamp in its local time. |
| pack-priv String | toString(int maximumDigits)
Returns the string representation (in Ion format) of this Timestamp in its local time. |
| public String | |
| public static Timestamp | Returns: null if the CharSequence is "null.timestamp"a sequence of characters that is the Ion representation of a
Timestamp ionFormattedTimestamp)Returns a new Timestamp that represents the point in time, precision
and local offset defined in Ion format by the |
| public Timestamp | withLocalOffset(Integer offset)
Returns a timestamp at the same point in time, but with the given local offset. |