简体   繁体   English

日期格式转换为 YYYY-MM-DD HH:MIN:SEC 在 Apache Hive

[英]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_timestampfrom_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.

相关问题 将日期格式从mmddyy转换为yyyy-mm-dd hh:mm:sec - convert date format from mmddyy to yyyy-mm-dd hh:mm:sec pyspark sql 将日期格式从 mm/dd/yy hh:mm 或 yyyy-mm-dd hh:mm:ss 转换为 yyyy-mm-dd hh:mm 格式 - pyspark sql convert date format from mm/dd/yy hh:mm or yyyy-mm-dd hh:mm:ss into yyyy-mm-dd hh:mm format SQL Server 日期转换 - yyyy-dd-mm hh:mm:ss 到 yyyy-mm-dd hh:mm:s - SQL Server date conversion - yyyy-dd-mm hh:mm:ss to yyyy-mm-dd hh:mm:s 尝试以(yyyy-mm-dd hh:mm:ss)日期格式转换字符串格式(dd-mm-yyyy hh:mm:ss) - Trying to convert string format (dd-mm-yyyy hh:mm:ss) in (yyyy-mm-dd hh:mm:ss) date format 如何将mm / dd / yyyy格式的日期转换为yyyy-mm-dd hh:mi:ss.mmm - How to convert date in mm/dd/yyyy format to yyyy-mm-dd hh:mi:ss.mmm Oracle中的时间戳转换为YYYY-MM-DD HH:MM:SS格式 - Timestamp conversion in Oracle for YYYY-MM-DD HH:MM:SS format 将mm / dd / yy hr:min:sec转换为yyyy-mm-dd hr:min:sec - Convert mm/dd/yy hr:min:sec to yyyy-mm-dd hr:min:sec 将 mm/dd/yyyy 传递给 yyyy-mm-dd 日期格式 - Pass mm/dd/yyyy to yyyy-mm-dd date format 如何查询日期格式YYYY-MM-dd HH-MM-ss? - How to query the date format YYYY-MM-dd HH-MM-ss? 我想以yyyy-mm-dd HH:mm:ss格式获取日期 - I want to Get Date in yyyy-mm-dd HH:mm:ss format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM