Java基础学习 Timestamp类

java.sql包下 继承了 java.util.Date

jdk1.8原代码对该类的解释:

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.
对Date类的一个封装,让jdbc API去明确这是一个SQL的TIMESTAMP值,
该类添加了纳秒的表现形式,同时提供格式化和解析操作

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.
Date与单独纳秒值的组合
Only integral seconds are stored in the java.util.Date component. The fractional seconds - the nanos - are separate.
整秒的值存储在Date中,纳秒是分开存储的
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.
该类的equals(Object) 不会返回true,当该Object不是Timestamp对象时
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.
该类对象的hashCode方法是使用底层的Date实现的 ,所以计算时不包括纳秒值

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.
由于Timestamp类与Date类不同,建议不要将Timestamp对象作为Date看待
The inheritance relationship between Timestamp and java.util.Date really denotes implementation inheritance, and not type inheritance.
Timestamp和Date之间的继承关系实际上表示实现继承,而不是类型继承。

通过我的理解是在Date类中添加了纳秒值private int nanos;

方法:
Java基础学习 Timestamp类