纪元转换关闭1秒

时间:2018-09-26 12:40:32

标签: oracle epoch

select from_tz(
         cast(
           to_date('1970-01-01 00','yyyy-mm-dd hh24')
             + (1536698971759)/1000/60/60/24
           as timestamp
         ),
         'GMT'
       ) at time zone 'US/Eastern'
from   dual;

产量:

11-SEP-18 04.49.32.000000 PM US/EASTERN

但是,如果您将1536698971759插入任何在线转换器,您将看到秒数实际上是3 1 ,而不是3 2

怎么了?

1 个答案:

答案 0 :(得分:3)

这是隐式舍入的问题。 let immutable = Map({ id: 1, title: 'title!'}); 数据类型(由于DATE)不支持小数秒,因此31.759舍入为32。

尝试这个:

TO_DATE()

SELECT (TIMESTAMP '1970-01-01 00:00:00 UTC' + 1536698971759/1000 * INTERVAL '1' SECOND) AT TIME ZONE 'US/Eastern' FROM dual; (如果愿意)

(TIMESTAMP '1970-01-01 00:00:00 UTC' + NUMTODSINTERVAL(1536698971759/1000, 'SECOND')) AT TIME ZONE 'US/Eastern'