Ian
Ian

Reputation: 1304

Hive timestamp ISO to UTC conversion

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?

Upvotes: 1

Views: 4208

Answers (1)

Nishu Tayal
Nishu Tayal

Reputation: 20820

One way is, you can write a Hive UDF for time format conversion.

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

Upvotes: 1

Related Questions