- All Implemented Interfaces:
Serializable, Cloneable, Comparable<Date>
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...] andsrepresents 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. Also, the hashCode
method uses the underlying java.util.Date
implementation and therefore does not include nanos in its computation.
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.
- Since:
- 1.1
- See Also:
Constructors
- =@Deprecated(since="1.2")
public Timestamp(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) - =public Timestamp(long arg0)
Methods
- =public boolean after(java.sql.Timestamp arg0)
- =public boolean before(java.sql.Timestamp arg0)
- =public int compareTo(java.util.Date arg0)
- =public int compareTo(java.sql.Timestamp arg0)
- =public boolean equals(java.lang.Object arg0)
- =public boolean equals(java.sql.Timestamp arg0)
- =public static java.sql.Timestamp from(java.time.Instant arg0)
- =public int getNanos()
- =public long getTime()
- ≠public int hashCode()Comparing JDBC 4.4 and JDBC 4.5
hashCode
public int hashCode()Returns a hash code value for this objectTimestamp. The result is the exclusive OR of the two halves of the primitivelongvalue returned by the Date.Moved out of a link with destination ../../../java.base/java/util/Date.html#getTime().Moved to a link with destination #getTime().Moved out of a link with destination ../../../java.base/java/util/Date.html#getTime().Moved to a link with destination #getTime().getTime()Moved out of a link with destination ../../../java.base/java/util/Date.html#getTime().Moved to a link with destination #getTime(). method. That is, the hash code is the value of the expression:Moved out of a quote.Moved to a division with class snippet-container.TheMoved out of a quote.Moved out of a preformatted block.Moved out of a computer code block.Moved to a division with class snippet-container.Moved to a preformatted block with class snippet and id snippet-hashCode()1.Moved to a computer code block with class language-java.(int)(this.getTime()^(this.getTime() >>> 32))Moved out of a quote.Moved out of a preformatted block.Moved to a division with class snippet-container.Moved to a preformatted block with class snippet and id snippet-hashCode()1.hashCodemethod uses the underlyingjava.util.Dateimplementation and therefore does not include nanos in its computation. - =public void setNanos(int arg0)
- =public void setTime(long arg0)
- =public java.time.Instant toInstant()
- =public java.time.LocalDateTime toLocalDateTime()
- =public java.lang.String toString()
- =public static java.sql.Timestamp valueOf(java.lang.String arg0)
- =public static java.sql.Timestamp valueOf(java.time.LocalDateTime arg0)
Serialized Form
=serialVersionUID
=2745179027874758501Serialized Fields
- =int nanos
Summary
| Elements | Comments | Descriptions | Total | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Added | Changed | Removed | Added | Changed | Removed | Added | Changed | Removed | ||
| Timestamp | 3 | 3 | ||||||||
| hashCode() | 1 | 5 | 3 | 9 | ||||||
| Total | 1 | 5 | 6 | 12 | ||||||