将字符串转换为火花/蜂巢中的时间戳
我需要将字符串转换为时间戳。
问题是输入来自 csv 文件,并包含日期时间值,例如:
3022年3022年3月3日上午
APR 27 2022 7:37 AM
如果我使用以下转换:
to_timestamp(to_timestamp(trim(datecolumn),'mmm dd yyyy h:mma'),'yyyy-mm-dd hh:mm:mm:ss')
它转换日期apr 27 2022 2022 7:37 AM
正确>正确地> ,但是在转换3022年3月3日上午3:30 AM
时引发错误,因为该月和日期值之间的额外空间,并且日期3不是03。
是否可以将这些2个字符串格式转换为DateTime?
I need to convert string to Timestamp.
The problem is that the input is coming from a csv file and contains date-time values such as:
Mar 3 2022 8:30AM
Apr 27 2022 7:37AM
If I use the following conversion:
to_timestamp(to_timestamp(trim(DateColumn), 'MMM dd yyyy h:mma'), 'yyyy-MM-dd HH:mm:ss')
It converts the date Apr 27 2022 7:37AM
correctly, but throws error while converting Mar 3 2022 8:30AM
because of the extra space between the Month and Date values and that the date 3 is not 03.
Is there a way to convert these 2 strings formats into Datetime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建议您首先用
单个空间
均匀地替换多个空格,然后转换为时间戳。It is recommended that you first uniformly replace multiple spaces with a
single space
, and then convert to timestamp.