互联网公司最关注的数据指标,停留时长,使用时长 等等指标计算出来一般单位都是数值单位,xx
秒,如30
秒,12782
秒
或者xx.xx
分钟,如4.5
分钟,
如果展现几分几秒的话,或许更直观,
比如12782
秒转换为03:33:02
或者是03时33分02秒
现在有两种办法实现:都是借助linux时间戳是从 1970-01-01 00:00:00开始的原理实现
from_unixtime 函数
hive> select from_unixtime(12782-8*60*60) ;
OK
1970-01-01 03:33:02
hive> select from_unixtime(12782-8*60*60,'HH时mm分ss秒'
OK
03时33分02秒
to_utc_timestamp 函数
hive> select to_utc_timestamp(12782*1000,'GMT+8');
OK
1970-01-01 03:33:02
hive> select substr(to_utc_timestamp(12782*1000,'GMT+8'),12,8);
OK
03:33:02
`