为什么 TO_UTC_TIMESTAMP 在 hive returns 错误的年份?
Why TO_UTC_TIMESTAMP in hive returns wrong year?
尝试 运行 在 hive CLI 中进行简单查询 -
select to_utc_timestamp(unix_timestamp("04/24/2017 01:59:01","MM/dd/YYYY HH:mm:ss"),'EST');
结果:
OK
1970-01-18 09:00:35.941
Time taken: 0.448 seconds, Fetched: 1 row(s)
输出不应该只是日期加上 4 小时吗?
我们开始吧。您需要将 unix_timestamp
包装在 from_unixtime
.
中
select to_utc_timestamp(from_unixtime(unix_timestamp('04/24/2017 01:59:01','MM/dd/yyyy hh:mm:ss'),'yyyy-MM-dd hh:mm:ss'),"EST");
yyyy
(而不是YYYY
)
unix_timestamp
returns bigint 和 to_utc_timestamp
将整数值视为毫秒
select to_utc_timestamp(1000*unix_timestamp("04/24/2017 01:59:01","MM/dd/yyyy HH:mm:ss"),'EST');
尝试 运行 在 hive CLI 中进行简单查询 -
select to_utc_timestamp(unix_timestamp("04/24/2017 01:59:01","MM/dd/YYYY HH:mm:ss"),'EST');
结果:
OK
1970-01-18 09:00:35.941
Time taken: 0.448 seconds, Fetched: 1 row(s)
输出不应该只是日期加上 4 小时吗?
我们开始吧。您需要将 unix_timestamp
包装在 from_unixtime
.
select to_utc_timestamp(from_unixtime(unix_timestamp('04/24/2017 01:59:01','MM/dd/yyyy hh:mm:ss'),'yyyy-MM-dd hh:mm:ss'),"EST");
yyyy
(而不是YYYY
)unix_timestamp
returns bigint 和to_utc_timestamp
将整数值视为毫秒
select to_utc_timestamp(1000*unix_timestamp("04/24/2017 01:59:01","MM/dd/yyyy HH:mm:ss"),'EST');