@Public public final class Timestamp extends Object implements Comparable<Timestamp>, Serializable
TimestampType
.
This data structure is immutable and consists of a milliseconds and nanos-of-millisecond since
1970-01-01 00:00:00
. It might be stored in a compact representation (as a long value) if
values are small enough.
Legacy: This class represents LocalZonedTimestampType
too, now it is recommended to
use LocalZoneTimestamp
.
Modifier and Type | Field and Description |
---|---|
static long |
MICROS_PER_MILLIS |
static long |
MILLIS_PER_DAY |
static long |
NANOS_PER_MICROS |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Timestamp that) |
boolean |
equals(Object obj) |
static Timestamp |
fromEpochMillis(long milliseconds)
Creates an instance of
Timestamp from milliseconds. |
static Timestamp |
fromEpochMillis(long milliseconds,
int nanosOfMillisecond)
Creates an instance of
Timestamp from milliseconds and a nanos-of-millisecond. |
static Timestamp |
fromInstant(java.time.Instant instant)
Deprecated.
use
LocalZoneTimestamp . |
static Timestamp |
fromLocalDateTime(java.time.LocalDateTime dateTime)
Creates an instance of
Timestamp from an instance of LocalDateTime . |
static Timestamp |
fromMicros(long micros)
Creates an instance of
Timestamp from micros. |
static Timestamp |
fromSQLTimestamp(Timestamp timestamp)
|
long |
getMillisecond()
Returns the number of milliseconds since
1970-01-01 00:00:00 . |
int |
getNanoOfMillisecond()
Returns the number of nanoseconds (the nanoseconds within the milliseconds).
|
int |
hashCode() |
static boolean |
isCompact(int precision)
Returns whether the timestamp data is small enough to be stored in a long of milliseconds.
|
static Timestamp |
now()
Creates an instance of
Timestamp for now. |
java.time.Instant |
toInstant()
Deprecated.
use
LocalZoneTimestamp . |
java.time.LocalDateTime |
toLocalDateTime()
Converts this
Timestamp object to a LocalDateTime . |
long |
toMicros()
Converts this
Timestamp object to micros. |
Timestamp |
toMillisTimestamp() |
Timestamp |
toSQLTimestamp()
|
String |
toString() |
public static final long MILLIS_PER_DAY
public static final long MICROS_PER_MILLIS
public static final long NANOS_PER_MICROS
public long getMillisecond()
1970-01-01 00:00:00
.public int getNanoOfMillisecond()
The value range is from 0 to 999,999.
public Timestamp toSQLTimestamp()
public Timestamp toMillisTimestamp()
public java.time.LocalDateTime toLocalDateTime()
Timestamp
object to a LocalDateTime
.@Deprecated public java.time.Instant toInstant()
LocalZoneTimestamp
.Timestamp
object to a Instant
.public long toMicros()
Timestamp
object to micros.public int compareTo(Timestamp that)
compareTo
in interface Comparable<Timestamp>
public static Timestamp fromEpochMillis(long milliseconds)
Timestamp
from milliseconds.
The nanos-of-millisecond field will be set to zero.
milliseconds
- the number of milliseconds since 1970-01-01 00:00:00
; a negative
number is the number of milliseconds before 1970-01-01 00:00:00
public static Timestamp fromEpochMillis(long milliseconds, int nanosOfMillisecond)
Timestamp
from milliseconds and a nanos-of-millisecond.milliseconds
- the number of milliseconds since 1970-01-01 00:00:00
; a negative
number is the number of milliseconds before 1970-01-01 00:00:00
nanosOfMillisecond
- the nanoseconds within the millisecond, from 0 to 999,999public static Timestamp fromLocalDateTime(java.time.LocalDateTime dateTime)
Timestamp
from an instance of LocalDateTime
.dateTime
- an instance of LocalDateTime
public static Timestamp fromSQLTimestamp(Timestamp timestamp)
timestamp
- an instance of Timestamp
@Deprecated public static Timestamp fromInstant(java.time.Instant instant)
LocalZoneTimestamp
.Timestamp
from an instance of Instant
.instant
- an instance of Instant
public static Timestamp fromMicros(long micros)
Timestamp
from micros.public static boolean isCompact(int precision)
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.