hive sql时间转换
舟率率 8/4/2023 sparkhive
-- 格式化输出转时间戳
-- 1570939200000
SELECT (unix_timestamp('2019-10-13 12:00:00', 'yyyy-MM-dd HH:mm:ss') - 8 * 60 * 60) * 1000;
-- 1570896000000
SELECT (unix_timestamp('2019-10-13', 'yyyy-MM-dd') - 8 * 60 * 60) * 1000;
-- 时间戳转格式化输出,2019-10-13 12:00:00
select date_format(from_utc_timestamp(1570939200000, "GMT+8"), 'yyyy-MM-dd') as local_time;
select date_format(from_utc_timestamp(1570939200000, "GMT+8"), 'yyyy-MM-dd HH:mm:ss') as local_time;
-- 日期转时间
select to_utc_timestamp('2019-10-13 12:00:00', "GMT");
select to_utc_timestamp('2019-10-13', "GMT");
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12