A thin wrapper around java.util.Date that allows
the JDBC API to identify this as an SQL TIMESTAMP value.
It adds the ability
to hold the SQL TIMESTAMP fractional seconds value, by allowing
the specification of fractional seconds to a precision of nanoseconds.
A Timestamp also provides formatting and
parsing operations to support the JDBC escape syntax for timestamp values.
The precision of a Timestamp object is calculated to be either:
19 , which is the number of characters in yyyy-mm-dd hh:mm:ss
20 + s , which is the number
of characters in the yyyy-mm-dd hh:mm:ss.[fff...] and s represents the scale of the given Timestamp,
its fractional seconds precision.
Note
This type is a composite of a java.util.Date and a
separate nanoseconds value. Only integral seconds are stored in the
java.util.Date component. The fractional seconds - the nanos - are
separate. The Timestamp.equals(Object) method never returns
true when passed an object
that isn't an instance of java.sql.Timestamp,
because the nanos component of a date is unknown.
As a result, the Timestamp.equals(Object)
method is not symmetric with respect to the
java.util.Date.equals(Object) method.
Due to the differences between the Timestamp class
and the java.util.Date
class mentioned above, it is recommended that code not view
Timestamp values generically as an instance of
java.util.Date. The
inheritance relationship between Timestamp
and java.util.Date really
denotes implementation inheritance, and not type inheritance.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private int | |
| pack-priv static final long |
| Access | Constructor and Description |
|---|---|
| public | Timestamp(int
the year minus 1900 year, int 0 to 11 month, int 1 to 31 date, int 0 to 23 hour, int 0 to 59 minute, int 0 to 59 second, int 0 to 999,999,999 nano)
Deprecated
since 1.2. instead use the constructor
Timestamp(long millis)
Constructs a |
| public | Timestamp(long
milliseconds since January 1, 1970, 00:00:00 GMT.
A negative number is the number of milliseconds before
January 1, 1970, 00:00:00 GMT. time)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public boolean | |
| public int | Returns: the value0 if the two Timestamp
objects are equal; a value less than 0 if this
Timestamp object is before the given argument;
and a value greater than 0 if this
Timestamp object is after the given argument.the ts)Timestamp object to be compared to
this Timestamp objectImplements java. Compares this |
| public int | Returns: the value0 if this Timestamp object
and the given object are equal; a value less than 0
if this Timestamp object is before the given argument;
and a value greater than 0 if this
Timestamp object is after the given argument.the o)Date to be compared to
this Timestamp objectOverrides java. Implements java. Compares this |
| public boolean | |
| public boolean | Returns: true if the given Object is an instance
of a Timestamp that
is equal to this Timestamp object;
false otherwisethe ts)Object value to compare withOverrides java. Tests to see if this |
| public static Timestamp | Returns: anTimestamp representing the same point on the time-line as
the provided instantthe instant to convert instant)Hides java. Obtains an instance of |
| public int | Returns: thisTimestamp object's fractional seconds componentGets this |
| public long | Returns: the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.Overrides java. Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by this |
| public int | Returns: a hash code value for this Timestamp.Overrides java. Returns a hash code value for this Timestamp. |
| public void | setNanos(int
the new fractional seconds component n)Sets this |
| public void | setTime(long
the number of milliseconds. time)Overrides java. Sets this |
| public Instant | Returns: an instant representing the same point on the time-lineOverrides java. Converts this |
| public LocalDateTime | Returns: aLocalDateTime object representing the same date-time valueConverts this |
| public String | Returns: aString object in
yyyy-mm-dd hh:mm:ss.fffffffff formatOverrides java. Formats a timestamp in JDBC timestamp escape format. |
| public static Timestamp | |
| public static Timestamp | Returns: aTimestamp objecta dateTime)LocalDateTime to convertObtains an instance of |
| MILLIS_PER_SECOND | back to summary |
|---|---|
| private static final int MILLIS_PER_SECOND | |
| nanos | back to summary |
|---|---|
| private int nanos | |
| serialVersionUID | back to summary |
|---|---|
| pack-priv static final long serialVersionUID | |
| Timestamp | back to summary |
|---|---|
| public Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
Deprecated since 1.2. instead use the constructor Constructs a
| |
| Timestamp | back to summary |
|---|---|
| public Timestamp(long time) Constructs a
| |
| after | back to summary |
|---|---|
| public boolean after(Timestamp ts) Indicates whether this
| |
| before | back to summary |
|---|---|
| public boolean before(Timestamp ts) Indicates whether this
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(Timestamp ts) Implements java. Compares this
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(Date o) Overrides java. Implements java. Compares this
| |
| equals | back to summary |
|---|---|
| public boolean equals(Timestamp ts) Tests to see if this
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object ts) Overrides java. Tests to see if this Note This method is not symmetric with respect to the
| |
| from | back to summary |
|---|---|
| public static Timestamp from(Instant instant) Hides java. Obtains an instance of
| |
| getNanos | back to summary |
|---|---|
| public int getNanos() Gets this
| |
| getTime | back to summary |
|---|---|
| public long getTime() Overrides java. Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
represented by this
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns a hash code value for this Timestamp. The result is the
exclusive OR of the two halves of the primitive (int)(this.getTime()^(this.getTime() >>> 32))
| |
| setNanos | back to summary |
|---|---|
| public void setNanos(int n) Sets this
| |
| setTime | back to summary |
|---|---|
| public void setTime(long time) Overrides java. Sets this
| |
| toInstant | back to summary |
|---|---|
| public Instant toInstant() Overrides java. Converts this
The conversion creates an | |
| toLocalDateTime | back to summary |
|---|---|
| public LocalDateTime toLocalDateTime() Converts this
The conversion creates a
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Formats a timestamp in JDBC timestamp escape format.
| |
| valueOf | back to summary |
|---|---|
| public static Timestamp valueOf(String s) Converts a
| |
| valueOf | back to summary |
|---|---|
| public static Timestamp valueOf(LocalDateTime dateTime) Obtains an instance of
The provided
| |