简体   繁体   中英

Timezone date format in Oracle

I have to convert a SYSDATE date to a specific date format. That format must be something like this: '2016-11-23T15:12:48Z' . I think this is a weird date format but is the requirements that I have.

This must be a date to send in a Web Service message.

In Oracle (12c or 11g) I have some function to transform a date in this specific format? Thanks.

That will give you ISO-8601 mentioned in comment:

select to_char(systimestamp,'YYYY-MM-DD"T"hh24:mi:sstzh:tzm') isodt from dual;

If you really want Z instead of timezone you can use:

    select to_char(cast(systimestamp as timestamp) at time zone 'UTC',
               'yyyy-mm-dd"T"hh24:mi:ss"Z"')
    from dual;

Since the "Z" in the timestamp format you're after means "This is in UTC" , you should first make sure your sysdate is returned in UTC. You can do this by using systimestamp and sys_extract_utc() like so:

select to_char(sys_extract_utc(systimestamp), 'yyyy-mm-dd"T"hh24:mi:ss"Z"') dt_as_utc
from dual;

DT_AS_UTC
--------------------
2016-11-28T10:33:49Z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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