public class Timestamp extends Date
在java.util.Date
允许JDBC API鉴定为SQL TIMESTAMP
值薄包装。它增加了持有的SQL TIMESTAMP
小数秒值的能力,允许小数秒的规格精度纳秒。时间戳还提供了格式化和分析操作,支持时间戳值JDBC转义语法。
一个时间戳对象的精确计算是:
19
,这是yyyy-mm-dd HH的字符数:MM:SS 20 + s
,这在yyyy-mm-dd HH的字符数:MM:SS FFF。[…]和s
代表规模给定的时间戳,其小数秒的精度。注:这种类型是一个java.util.Date
和单独的纳秒值复合。只有积分秒存储在java.util.Date
组件。分数秒-纳米-是分开的。该方法不返回Timestamp.equals(Object)
true
时通过一个对象不是java.sql.Timestamp
实例,因为日期的纳米成分是未知的。作为一个结果,这Timestamp.equals(Object)
方法不是相对于java.util.Date.equals(Object)
方法对称。同时,该hashCode
方法使用底层的java.util.Date
实施,因此不包括在计算纳米。
由于该Timestamp
类和上面提到的java.util.Date
类之间的差异,建议代码不认为Timestamp
值一般为java.util.Date
实例。Timestamp
和java.util.Date
真是实现继承之间的继承关系,而不是类型继承。
Constructor and Description |
---|
Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
过时的。
相反,使用构造函数
Timestamp(long millis)
|
Timestamp(long time)
使用毫秒时间价值构建
Timestamp 对象。
|
Modifier and Type | Method and Description |
---|---|
boolean |
after(Timestamp ts)
指示此
Timestamp 对象是迟了
Timestamp 对象。
|
boolean |
before(Timestamp ts)
指示此
Timestamp 对象比给定的
Timestamp 对象之前。
|
int |
compareTo(Date o)
比较这
Timestamp 对象到给定的
Date 对象。
|
int |
compareTo(Timestamp ts)
比较这
Timestamp 对象到给定的
Timestamp 对象。
|
boolean |
equals(Object ts)
测试看看这
Timestamp 对象是否等于给定对象。
|
boolean |
equals(Timestamp ts)
测试看看这
Timestamp 对象等于给定
Timestamp 对象。
|
static Timestamp |
from(Instant instant)
获得
Timestamp 实例从一个
Instant 对象。
|
int |
getNanos()
得到这个
Timestamp 对象的
nanos 价值。
|
long |
getTime()
返回毫秒数自1970年1月1日以来,该
Timestamp 对象表示00:00:00 GMT。
|
int |
hashCode()
返回此对象的哈希代码值。
|
void |
setNanos(int n)
设置为给定值这
Timestamp 对象的
nanos 场。
|
void |
setTime(long time)
集代表一个时间点是1970年1月1日00:00:00 GMT
time毫秒后这
Timestamp 对象
|
Instant |
toInstant()
将这一
Instant
Timestamp 对象。
|
LocalDateTime |
toLocalDateTime()
将这一
LocalDateTime
Timestamp 对象。
|
String |
toString()
格式的时间戳格式的时间戳的JDBC逃跑。
|
static Timestamp |
valueOf(LocalDateTime dateTime)
获得
Timestamp 实例从
LocalDateTime 对象,同年,月,日,小时,分钟,秒和Nano的日期时间值为
LocalDateTime 。
|
static Timestamp |
valueOf(String s)
JDBC中的时间戳格式转换逃避
String 对象到
Timestamp 价值。
|
after, before, clone, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTimezoneOffset, getYear, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setYear, toGMTString, toLocaleString, UTC
@Deprecated public Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
Timestamp(long millis)
Timestamp
对象与给定的值初始化。
year
年减1900
month
- 0至11
date
- 1至31
hour
- 0至23
minute
- 0至59
second
- 0至59
nano
- 0至999999999
IllegalArgumentException
如果纳米的说法是出界
public Timestamp(long time)
Timestamp
对象。积分秒存储在底层的日期值;分数秒存储在对象的
Timestamp
nanos
场。
time
-自1970年1月1日00:00:00 GMT毫秒,负数在1970年1月1日之前的毫秒数,00:00:00 GMT。
Calendar
public void setTime(long time)
Timestamp
对象
setTime
方法重写,继承类
Date
time
-毫秒数。
getTime()
,
Timestamp(long time)
,
Calendar
public long getTime()
Timestamp
对象表示00:00:00 GMT。
getTime
方法重写,继承类
Date
setTime(long)
public static Timestamp valueOf(String s)
String
对象到
Timestamp
价值。
s
-
yyyy-[m]m-[d]d hh:mm:ss[.f...]
时间戳格式。分数秒可以省略。领先的零
mm
和
dd
也可以省略。
Timestamp
价值
IllegalArgumentException
如果给出的说法没有格式
yyyy-[m]m-[d]d hh:mm:ss[.f...]
public String toString()
yyyy-mm-dd hh:mm:ss.fffffffff
,哪里
ffffffffff
表明纳秒。
toString
方法重写,继承类
Date
yyyy-mm-dd hh:mm:ss.fffffffff
格式的
String
对象
Date.toLocaleString()
,
Date.toGMTString()
public int getNanos()
Timestamp
对象的
nanos
价值。
Timestamp
对象的分数秒分量
setNanos(int)
public void setNanos(int n)
Timestamp
对象的
nanos
场。
n
-新的分数秒分量
IllegalArgumentException
-如果给定的参数是大于999999999或小于0
getNanos()
public boolean equals(Timestamp ts)
Timestamp
对象等于给定
Timestamp
对象。
ts
-比较与
Timestamp
价值
true
如果给定的
Timestamp
对象等于这
Timestamp
对象;
false
否则
public boolean equals(Object ts)
Timestamp
对象是否等于给定对象。这个版本的方法
equals
已添加到固定
Timestamp.equals(Timestamp)
不正确的签名和与现有的类文件保持向后兼容性。注意:这个方法是不是在基类中的方法就
equals(Object)
对称。
equals
方法重写,继承类
Date
ts
-比较与
Object
价值
true
如果给定的
Object
是一
Timestamp
等于这
Timestamp
对象的一个实例;
false
否则
Date.getTime()
public boolean before(Timestamp ts)
Timestamp
对象比给定的
Timestamp
对象之前。
ts
-
Timestamp
价值比较
true
Timestamp
对象
false
否则早;
public boolean after(Timestamp ts)
Timestamp
对象是迟了
Timestamp
对象。
ts
-比较与
Timestamp
价值
true
Timestamp
对象之后;
false
否则
public int compareTo(Timestamp ts)
Timestamp
对象到给定的
Timestamp
对象。
ts
-
Timestamp
对象加以比较,这
Timestamp
对象
0
如果两
Timestamp
对象是否相等;如果这个值小于
0
Timestamp
对象在给定的参数;和一个值大于
0
如果这
Timestamp
对象是给定参数后。
public int compareTo(Date o)
Timestamp
对象到给定的
Date
对象。
compareTo
接口
Comparable<Date>
compareTo
方法重写,继承类
Date
o
-
Date
加以比较,这
Timestamp
对象
0
如果这
Timestamp
对象与给定的对象是平等的;如果这个值小于
0
Timestamp
对象在给定的参数;和一个值大于
0
如果这
Timestamp
对象是给定参数后。
public int hashCode()
Date.getTime()
方法返回。那是,哈希代码表达式的值:
的(int)(this.getTime()^(this.getTime() >>> 32))
hashCode
方法使用底层的
java.util.Date
实施,因此不包括在计算纳米。
hashCode
方法重写,继承类
Date
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public static Timestamp valueOf(LocalDateTime dateTime)
Timestamp
实例从
LocalDateTime
对象,同年,月,日,小时,分钟,秒和Nano的日期时间值为
LocalDateTime
。
提供的LocalDateTime
被解释为在本地时区的当地时间。
dateTime
-
LocalDateTime
转换
Timestamp
对象
NullPointerException
-如果
dateTime
是空的。
public LocalDateTime toLocalDateTime()
LocalDateTime
转换创建一个LocalDateTime
表示相同的年,月,日,小时,分钟,秒和Nano的日期时间值作为这Timestamp
在本地时区。
Timestamp
对象。
LocalDateTime
对象
public static Timestamp from(Instant instant)
instant
-转换的瞬间
Timestamp
NullPointerException
-如果
instant
是空的。
IllegalArgumentException
-如果瞬间太大代表一个
Timesamp
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.