Hive时间戳ISO到UTC转换 [英] Hive timestamp ISO to UTC conversion
问题描述
我有带ISO 8601时间戳的字符串,例如 2016-03-07T10:02:37.820 + 01:00
,我想将它们转换为UTC时间。内置的 to_utc_timestamp
(AFAIK)仅采用时区名称(例如PST,CET),而不采用偏移量。至少我尝试过并失败了。
I have strings with ISO 8601 timestamps like 2016-03-07T10:02:37.820+01:00
and I would like to convert them to UTC time. The built-in to_utc_timestamp
(AFAIK) only takes time zone names (e.g. PST, CET) and not the offsets. At least I tried and failed. Is there an elegant way to achieve this in Hive?
推荐答案
一种方法是,您可以编写Hive UDF进行时间格式转换。
One way is, you can write a Hive UDF for time format conversion.
另一种方法是,使用 unix_timestamp
将ISO时间戳转换为秒,然后使用 to_utc_timestamp
Another way is, convert ISO timestamps to seconds using unix_timestamp
and then use to_utc_timestamp
TO_UTC_TIMESTAMP(UNIX_TIMESTAMP(T.date, "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'") * 1000, '<timezone>')
这篇关于Hive时间戳ISO到UTC转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!