要求:将纪元转换为时间戳
问题:它正在转换为本地时区
当我在线手动检查时,如下所示
预期输出为
2017-12-15 09:21:15 | 2017-12-19 14:21:59
答案 0 :(得分:2)
从纪元获取时间戳的最简单方法是TO_TIMESTAMP()
。但是,如果您还想使用时区,则需要带有时区的时间戳。为此,请使用TO_TIMESTAMP_TZ()
。
SELECT TO_TIMESTAMP(1513347675), TO_TIMESTAMP(1513711319)
, TO_TIMESTAMP_TZ(1513347675), TO_TIMESTAMP_TZ(1513711319)
# 17-12-15 14:21
# 17-12-19 19:21
# 17-12-15 09:21
# 17-12-19 14:21
-
完整示例:
ALTER SESSION SET TIMESTAMP_TZ_OUTPUT_FORMAT = 'YY-MM-DD HH24:MI TZHTZM';
ALTER SESSION SET TIMEZONE = 'Etc/GMT';
SELECT TO_TIMESTAMP_TZ(1513347675);
-- 17-12-15 14:21 +0000
ALTER SESSION SET TIMEZONE = 'US/Eastern';
SELECT TO_TIMESTAMP_TZ(1513347675);
-- 17-12-15 09:21 -0500
ALTER SESSION SET TIMEZONE = 'US/Pacific';
SELECT TO_TIMESTAMP_TZ(1513347675);
-- 17-12-15 06:21 -0800