简体   繁体   English

Oracle SQL,格林威治标准时间 (UTC) 中的日期和时间

[英]Oracle SQL, Date and Time in GMT (UTC)

This coding is giving the correct answer for SYSDATE此编码为 SYSDATE 提供了正确答案

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

1662482430 (seconds) 

I need to return the date / time in GMT/UTC.我需要以 GMT/UTC 返回日期/时间。

I need help with the syntax.我需要语法方面的帮助。

Thanks, Pete谢谢,皮特

If you use SYSTIMESTAMP instead of SYSDATE then that value will be in your DB time zone, and you can then convert that to UTC with at time zone :如果您使用 SYSTIMESTAMP 而不是 SYSDATE 那么该值将在您的数据库时区中,然后您可以使用at time zone将其转换为 UTC:

SYSTIMESTAMP at time zone 'UTC'

and cast that back to a date:并将其恢复为日期:

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

and then use that in your calculation:然后在你的计算中使用它:

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

db<>fiddle db<>小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM