我正在编写一个程序,我从数据库中得到时区偏移量,我的要求是用时区偏移量操纵本地时间以获得UTC时间。
例如,
If local time is : 2/3/2013 2:05:53.000000 PM
timezone offset is : 5:30
Output should be : 2/3/2013 8:35:53.000000 AM (2/3/2013 2:05:53.000000 PM - 5:30)
任何人都可以为我提供适当的功能。
答案 0 :(得分:4)
使用Datetime Expressions,您可以更加通用:
SELECT FROM_TZ(TIMESTAMP '2013-02-03 14:05:53', '05:30') AT TIME ZONE 'UTC'
FROM dual;
或
SELECT (TIMESTAMP '2013-02-03 14:05:53' AT TIME ZONE '05:30') AT TIME ZONE 'UTC'
FROM dual;
答案 1 :(得分:2)
您可以使用FROM_TZ形成TIMESTAMP WITH TIME ZONE值 通过组合TIMESTAMP和TIME ZONE。接下来,使用SYS_EXTRACT_UTC 将其转换为UTC时间。
SQL> select from_tz(timestamp'2013-02-03 14:05:53','05:30'),
sys_extract_utc(from_tz(timestamp'2013-02-03 14:05:53','05:30'))
from dual;
FROM_TZ(TIMESTAMP'2013-02-0314:05:53','05:30') SYS_EXTRACT_UTC(FROM_TZ(TIMESTAMP'2013-02-0314:05:53','05:30'))
------------------------------------------------- -----------------------------------------------------------------
03-FEB-13 02.05.53.000000000 PM +05:30 03-FEB-13 08.35.53.000000000 AM