问题
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