Hive 的 unix_timestamp 和 from_unixtime 函数 [英] Hive's unix_timestamp and from_unixtime functions

查看:38
本文介绍了Hive 的 unix_timestamp 和 from_unixtime 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是 unix_timestampfrom_unixtime Hive 函数彼此反向".

I am under the impression that unix_timestamp and from_unixtime Hive functions are 'reverse' of each other.

当我尝试在 Hive 中将时间戳字符串转换为秒时:

When I try to convert timestamp string to seconds in Hive:

SELECT unix_timestamp('10-Jun-15 10.00.00.000000 AM', 'dd-MMM-yy hh.mm.ss.MS a');

我收到 1418176800.

I get 1418176800.

当我尝试将 1418176800 转换为时间戳字符串时:

When I try to convert 1418176800 to timestamp string:

SELECT from_unixtime(1418176800, 'dd-MMM-yy hh.mm.ss.MS a');

我得到 10-Dec-14 10.00.00.120 AM,这显然不等于原来的.

I get 10-Dec-14 10.00.00.120 AM, which is obviously not equal to the original.

谁能解释一下这是怎么回事?谢谢.

Can someone explain what's going on? Thanks.

推荐答案

来自语言手册:

将具有给定模式的时间字符串转换为 Unix 时间戳(以秒为单位)此函数的结果以秒为单位.

Convert time string with given pattern to Unix time stamp (in seconds) The result of this function is in seconds.

您的结果随日期的毫秒部分而变化,但 unix 函数仅支持秒.例如:

Your result changes with the milliseconds portion of the date, but the unix functions only support seconds. For example:

SELECT unix_timestamp('10-Jun-15 10.00.00 AM', 'dd-MMM-yy hh.mm.ss a');

1433930400

SELECT from_unixtime(1433930400, 'dd-MMM-yy hh.mm.ss a');

2015 年 6 月 10 日上午 10 点

10-Jun-15 10.00.00 AM

这篇关于Hive 的 unix_timestamp 和 from_unixtime 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆