我有一个包含日期列的表。我认为该列中的日期以UTC格式保存。
我希望在检索日期时以当地时间打印。这意味着当我从德国打电话给日期时,结果应该是这样的:
2015-04-29 11:24:06 +0200UTC EUROPE/BERLIN
我尝试了以下sql:
SELECT TO_CHAR(CAST(dateColum as TIMESTAMP WITH LOCAL TIME ZONE), 'YYYY-MM-DD HH24:MI:SS TZR') from myTable;
结果如下:
2015-04-29 11:24:06 EUROPE/BERLIN
+/-偏移丢失。
有什么想法吗?
答案 0 :(得分:6)
Oracle安装程序:
CREATE TABLE table_name ( value ) AS
SELECT DATE '2016-07-13' FROM DUAL;
<强>查询强>:
SELECT TO_CHAR(
FROM_TZ( CAST( value AS TIMESTAMP ), 'UTC' )
AT TIME ZONE 'EUROPE/BERLIN',
'YYYY-MM-DD HH24:MI:SS TZH:TZM TZR'
) AS berlin_time
FROM table_name;
<强>输出强>:
BERLIN_TIME
----------------------------------------
2016-07-13 02:00:00 +02:00 EUROPE/BERLIN
查询2 :
SELECT TO_CHAR(
FROM_TZ( CAST( value AS TIMESTAMP ), 'UTC' ) AT LOCAL,
'YYYY-MM-DD HH24:MI:SS TZH:TZM TZR'
) AS local_time
FROM table_name;
<强>输出强>:
LOCAL_TIME
----------------------------------------
2016-07-13 02:00:00 +02:00 EUROPE/BERLIN