gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 08:02:45 25 4
gpt4 key购买 nike

一天有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com