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