Oracle SQL,以GMT(UTC)表示的日期和时间



此编码为SYSDATE 提供了正确答案

select round((SYSDATE - date '1970-01-01')*24*60*60) from dual;
1662482430 (seconds) 

我需要返回GMT/UTC的日期/时间。

我需要语法方面的帮助。

谢谢,Pete

如果您使用SYSTIMESTAMP而不是SYSDATE,则该值将在您的DB时区中,然后您可以使用at time zone:将其转换为UTC

SYSTIMESTAMP at time zone 'UTC'

并将其追溯到一个日期:

cast(SYSTIMESTAMP at time zone 'UTC' as date)

然后在计算中使用:

select round((cast(SYSTIMESTAMP at time zone 'UTC' as date) - date '1970-01-01')*24*60*60)
from dual;

db<gt;小提琴

最新更新