[英]Date format conversion to YYYY-MM-DD HH:MIN:SEC in Apache Hive
I am loading data to a hive table from a csv file.我正在将数据从 csv 文件加载到 hive 表中。 File is having a field named last_updated_date and it's value is in format "20200412013000771+0000".
文件有一个名为 last_updated_date 的字段,其值的格式为“20200412013000771+0000”。 I need to covert it into "YYYY-MM-DD HH:MIN:SEC".
我需要将其转换为“YYYY-MM-DD HH:MIN:SEC”。
You can either chop it up with lots of substrings and rebuild it with concats, or strip off the irrelevant characters at the end and use unix_timestamp
and from_unixtime
.您可以使用大量子字符串将其拆分并使用 concats 重建它,或者在最后去除不相关的字符并使用
unix_timestamp
和from_unixtime
。
Since you don't care about milliseconds, you only want the first 14 chars.由于您不关心毫秒,因此您只需要前 14 个字符。 Here's how I'd go about it:
以下是我对 go 的看法:
select from_unixtime (unix_timestamp(substring('20200412013000771+0000',1,14), 'yyyyMMddhhmmss'))
Which returns哪个返回
2020-04-12 01:30:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.