在 Hive 中将 'Mon Dec 12 10:55:11 UTC 2016' 转换为日期时间

Convert 'Mon Dec 12 10:55:11 UTC 2016' to datetime in Hive

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

Mon Dec 12 10:55:11 UTC 2016

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

使用unix_timestamp(string date, string pattern) 转换given format to seconds passed from 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'));

Returns:

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');

Returns:

2016-12-12