Display Time Zone description in to_char() in Oracle

无人久伴 提交于 2021-01-27 06:30:27

问题


I have a SQL query

select to_char(cast(sysdate as timestamp with LOCAL time zone), 'YYYY-MM-DD, HH24:MI:SS TZR') from dual

This return output as

2015-08-06, 04:09:10 +05:30 

Anyone have any clue to get output as follows

2015-08-06, 04:09:10 IST

Thanks in advance.


回答1:


In general you cannot show time zone of TIMESTAMP WITH LOCAL TIME ZONE value, because it is always your current local time zone by definition.

+05:30 is your current time zone, you can verify by this:

SELECT SESSIONTIMEZONE FROM dual;

You cannot do

ALTER SESSION SET TIME_ZONE = 'IST';

Because IST is also used for "Iceland Standard Time", "Ireland Standard Time", "Israel Standard Time", etc.

However, you can use this:

SELECT TO_CHAR(CAST(LOCALTIMESTAMP AS TIMESTAMP WITH LOCAL TIME ZONE), 'YYYY-MM-DD, HH24:MI:SS TZD') FROM dual;

Note, TZD means "Daylight savings information". In case India has Daylight saving your TZD may change.




回答2:


I have converted the TIMESTAMP To UTC and added 5.5 hrs to it. Like below

SELECT TO_CHAR(SYS_EXTRACT_UTC(systimestamp) + (5.5/24))|| ' IST' FROM DUAL;

Hope this works for you.



来源:https://stackoverflow.com/questions/31858149/display-time-zone-description-in-to-char-in-oracle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!