简体   繁体   English

如何从Oracle中包含时区偏移量的日期/时间字符串中获取UTC日期/时间

[英]How to get UTC date/time from a date/time string that contains timezone offset in Oracle

Given a string like this: '2015-11-23T07:00:10.563-04:00' I am trying to determine the UTC date/time which I would expect to be: '2015-11-23 11:00:10.5630000' 给定这样的字符串:'2015-11-23T07:00:10.563-04:00'我试图确定我希望成为的UTC日期/时间:'2015-11-23 11:00:10.5630000'

I have tried the following: 我尝试了以下方法:

SELECT sys_extract_utc(
        to_timestamp_tz('2015-11-23T07:00:10.563-04:00', 
                        'yyyy-mm-dd"T"hh24:mi:ss.FF TZH:TZM')
         )  
FROM DUAL;

but this produces the result: 但这会产生结果:

2015/11/23 03:00:10.563000000

Even when I change the timezone offset to positive, I get the same result. 即使将时区偏移量更改为正值,我也得到相同的结果。 I must be misunderstanding something so would appreciate your help. 我一定误会了一些东西,希望能帮助您。

There is no space between fractional seconds and timezone hour. 小数秒与时区小时之间没有空格。 So remove space from you pattern, and it'll give desired result. 因此,从您的图案中删除空间,它将获得所需的结果。

SQL> SELECT sys_extract_utc(to_timestamp_tz('2015-11-23T07:00:10.563-04:00', 'yyyy-mm-dd"T"hh24:mi:ss.FFTZH:TZM'))  
FROM DUAL; 

SYS_EXTRACT_UTC(TO_TIMESTAMP_TZ('2015-11-23T07:00:10.563-04:00','YYYY-MM-DD
---------------------------------------------------------------------------
23-NOV-15 11.00.10.563000000 AM

Fixed it - the space character between ".....hh24:mi:ss.FF TZH:TZM" was causing the problem. 修复了它-“ ..hh24:mi:ss.FF TZH:TZM”之间的空格字符导致了此问题。

This now works perfectly: 现在可以完美运行:

SELECT sys_extract_utc(to_timestamp_tz('2015-11-23T07:00:10.563+04:00', 'yyyy-mm-dd"T"hh24:mi:ss.FFTZH:TZM'))  FROM DUAL;

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

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