oracle DATE 和 TIMESTAMP 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19141030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:18:27  来源:igfitidea点击:

Difference between oracle DATE and TIMESTAMP

oraclejdbcoracle11g

提问by supernova

What are the difference between Oracle DATE and TIMESTAMP type? Both have date and time component? Also what is corresponding type in Java for these date types?

Oracle DATE 和 TIMESTAMP 类型有什么区别?两者都有日期和时间组件?另外,这些日期类型在 Java 中对应的类型是什么?

回答by Guillermo Luque

DATE and TIMESTAMP have the same size (7 bytes). Those bytes are used to store century, decade, year, month, day, hour, minute and seconds. But TIMESTAMP allows to store additional info such as fractional seconds (11 bytes) and fractional seconds with timezone (13 bytes).

DATE 和 TIMESTAMP 具有相同的大小(7 个字节)。这些字节用于存储世纪、十年、年、月、日、小时、分钟和秒。但是 TIMESTAMP 允许存储其他信息,例如小数秒(11 字节)和带时区的小数秒(13 字节)。

TIMESTAMP was added as an ANSI compliant to Oracle. Before that, it had DATE only.

TIMESTAMP 被添加为符合 Oracle 的 ANSI。在此之前,它只有 DATE。

In general cases you should use DATE. But if precision in time is a requirement, use TIMESTAMP.

在一般情况下,您应该使用 DATE。但如果需要时间精度,请使用 TIMESTAMP。

And about Java, the oracle.sql.DATE class from Oracle JDBC driver, provides conversions between the Oracle Date/Timestamp data type and Java classes java.sql.Date, java.sql.Time and java.sql.Timestamp.

关于 Java,来自 Oracle JDBC 驱动程序的 oracle.sql.DATE 类提供 Oracle 日期/时间戳数据类型与 Java 类 java.sql.Date、java.sql.Time 和 java.sql.Timestamp 之间的转换。