zoukankan      html  css  js  c++  java
  • Hive presto和hive时间格式转换

    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'

  • 相关阅读:
    CSS3:三个矩形,一个宽200px,其余宽相等且自适应满铺
    pidera安装node.js(树莓派)
    深入JavaScript模块化编程
    c# 多显示器设置主屏幕(Set primary screen for multiple monitors)
    c# 获取移动硬盘信息、监听移动设备的弹出与插入事件
    C# 弹出USB外接硬盘(U盘)
    log4net 自定义Appender
    Scrum 思考
    监控浏览器关闭事件
    判断地图的点是否在面内 腾讯地图
  • 原文地址:https://www.cnblogs.com/lixiaozhi/p/11882007.html
Copyright © 2011-2022 走看看