1、北京時間格式 to unix時間格式
數據格式: 2017-11-17 08:28:13 2017-11-17 08:28:10 2017-11-17 08:27:51.343 2017-11-17 08:27:48.021 |
presto單個標准時間轉化(10位unix): select to_unixtime(cast ('2017-08-30 10:36:15' as timestamp))
hive單個標准時間轉化(10位unix): select unix_timestamp(cast ('2017-08-30 10:36:15' as timestamp)) |
presto單個毫秒時間轉化(13位unix): select to_unixtime(cast ('2017-12-01 16:42:08.771' as timestamp))
hive單個毫秒時間轉化(自動轉為10位unix): select unix_timestamp(cast ('2017-12-01 16:42:08.771' as timestamp)) |
presto變量轉化(根據時間格式分別轉化為10位unix、13位unix): select to_unixtime(cast (time as timestamp)) from table1
hive變量轉化(只能自動轉化為10位unix): select unix_timestamp(cast (time as timestamp)) from table1 where d = '2017-12-05' |
2、unix時間格式 to 北京時間格式
數據格式: 1510894478 1510855235 1510855290929 1510873252377 |
presto單個10位unix(變為標准格式): select format_datetime(from_unixtime(1510284058),'yyyy-MM-dd HH:mm:ss')
hive單個10位unix(變為標准格式): select from_unixtime(1323308943123,'yyyy-MM-dd HH:mm:ss') |
presto單個13位unix(毫秒格式): select format_datetime(from_unixtime(1510284058.415),'yyyy-MM-dd HH:mm:ss.mmm')
hive單個13位unix(毫秒格式):手動截取10位 select from_unixtime(cast(substr(1323308943123,1,10) as int),'yyyy-MM-dd HH:mm:ss') |
Presto 13、10位unix變量轉化(只能截取成10位轉化成標准格式): select format_datetime(from_unixtime(cast(substr(ts,1,10) as double)),'yyyy-MM-dd HH:mm:ss') from table1
hive變量轉化(事先截取10位unix): select from_unixtime(cast(substr(ts,1,10) as int),'yyyy-MM-dd HH:mm:ss') from table1 where d = '2017-12-05' |