【问题标题】:Convert 'Mon Dec 12 10:55:11 UTC 2016' to datetime in Hive将 'Mon Dec 12 10:55:11 UTC 2016' 转换为 Hive 中的日期时间
【发布时间】:2019-09-30 08:58:38
【问题描述】:

我无法在 Hive 中将以下字符串转换为日期时间。

Mon Dec 12 10:55:11 UTC 2016

我用过date_format('Mon Dec 12 10:55:11 UTC 2016','dd-MM-yyyy')。但结果我得到了NULL。 任何帮助将不胜感激。

【问题讨论】:

    标签: datetime hadoop hive timestamp hiveql


    【解决方案1】:

    使用unix_timestamp(string date, string pattern)given format 中的字符串转换为从Unix Epoch (1970-01-01 00:00:00 UTC) 传递的秒数。

    然后使用from_unixtime() 转换为required format

    演示:

    您的初始格式是'EEE MMM dd HH:mm:ss z yyyy'

    转换为yyyy-MM-dd HH:mm:ss(默认):

    select from_unixtime(unix_timestamp('Mon Dec 12 10:55:11 UTC 2016','EEE MMM dd HH:mm:ss z yyyy'));
    

    返回:

    2016-12-12 10:55:11 
    

    转换为yyyy-MM-dd

    select from_unixtime(unix_timestamp('Mon Dec 12 10:55:11 UTC 2016','EEE MMM dd HH:mm:ss z yyyy'),'yyyy-MM-dd');
    

    返回:

    2016-12-12
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-18
      • 2017-05-09
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多