hive 时间函数问题

把当前时间转换成 unix 时间戳

select unix_timestamp();        

取正确的当前时间,用current_timestamp  函数

select current_timestamp();      

select date_format(current_timestamp,'yyyy-MM-dd HH:mm:ss');


如果用 from_unixtime 时间函数取当前系统时间会发现比系统时间早了 8个小时

select   from_unixtime(1649905154, "yyyy-MM-dd HH:mm:ss");

select  from_unixtime(unix_timestamp(), "yyyy-MM-dd HH:mm:ss");

加8个小时,能正确取到当前时间

select from_unixtime(cast('1649905154' as bigint) + 28800,'yyyyMMdd HH:mm:ss');


hive 时区问题

新版本 hive 3.1.2 ,时区是LOCAL 本地时区 上海时区

select current_timestamp();  取的是当前正确的时间

而老版本hive 3.1.0  时区是UTC , 取得时间会比当前时间早 8 个小时

因此新版本hive 可以设置时区 set hive.local.time.zone=UTC ;   老版本hive 时间保持一致。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容