java - 为什么 java.sql.Date.getTime() 对于 1970-01-02 返回 82_800_000 而不是 86_400_000?

标签 java time epoch

一天有 86400 秒。许多时间对象与 1970-01-01 的纪元有关。 API 说

A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT

以下代码返回 82800000。为什么?怎么了?

java.sql.Date sqlDate = java.sql.Date.valueOf( "1970-01-02" );
long millis = sqlDate.getTime();
System.out.println( "expected=" + 86400000 + " " + sqlDate
            + "\n  result=" + millis );

最佳答案

A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT

因此,如果您的时区是 GMT+1,您将获得 1970 年 1 月 2 日的 82800000:

(1970 年 1 月 1 日 + 一天 - 一小时)

关于java - 为什么 java.sql.Date.getTime() 对于 1970-01-02 返回 82_800_000 而不是 86_400_000?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36662473/

相关文章:

java - 如何用java生成动态报告

java - 如何使用 JSQLParser 获取 Select 子句的主体

java - 使用正则表达式从使用 xeger java 库生成的字符串中解析 id

powershell - 对 CSV Powershell 中的值进行数学运算

python - Selenium Python - 显式等待不起作用

java - 在重复任务中调用 'this' 时出现静态问题

php - 将 mysql TIME 从 24 HR 转换为 AM/PM 格式

java - 如何在 Java 中将 ZonedDateTime 转换为毫秒?

javascript - 将纪元时间转换为人类可读时间

java - System.currentTimeMillis 的长度