Oracle conversion of UNIX timestamp to timestamp with time zone

丶灬走出姿态 提交于 2019-12-02 22:09:54

问题


Trying to convert UNIX timestamp to Oracle timestamp with timezone. Expecting to see different output, however datetime part is the same.

What is wring ?

select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('EST') from dual;

Output: 27-FEB-08 09.21.56.656000000 AM -05:00

select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('PST') from dual;

Output: 27-FEB-08 09.21.56.656000000 AM -07:00

How come date / time part is the same? Does not Oracle do adjustment ?


回答1:


Unix timestamp is from 1970-01-01 00:00:00 UTC. When you just do timestamp '1970-01-01 00:00:00' Oracle takes your local time zone!

You have to do it like this:

(TIMESTAMP '1970-01-01 00:00:00' AT TIME ZONE 'UTC' +     
    numtodsinterval(1204104116656/1000,'second')) AT time zone tz_offset('PST');

`



来源:https://stackoverflow.com/questions/31483658/oracle-conversion-of-unix-timestamp-to-timestamp-with-time-zone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!