简体   繁体   English

如何在 Athena 中将 GMT 字符串转换为日期

[英]How to convert string with GMT to date in Athena

I have a column filled with dates in string format, eg 2023-01-31 11:21:33 GMT .我有一列以字符串格式填充日期,例如2023-01-31 11:21:33 GMT

I am trying to write a query that will select a year and a month and will do some calculations later on.我正在尝试编写一个查询,该查询将 select 一年零一个月,稍后将进行一些计算。 My standard approaches using EXTRACT(YEAR FROM a)) etc. did not work.我使用EXTRACT(YEAR FROM a))等的标准方法不起作用。 Therefore, I am trying to parse datetime using PARSE_DATETIME(a, 'yyyy-mm-dd hh:mm:ss') .因此,我正在尝试使用PARSE_DATETIME(a, 'yyyy-mm-dd hh:mm:ss')解析日期时间。 The thing is, I don't know how to format "GMT" and google did not help with that.问题是,我不知道如何格式化“GMT”,而谷歌对此没有帮助。

The error message is INVALID_FUNCTION_ARGUMENT: Invalid format: "2023-01-31 11:21:33 GMT" is malformed at "GMT" .错误消息是INVALID_FUNCTION_ARGUMENT: Invalid format: "2023-01-31 11:21:33 GMT" is malformed at "GMT"

Use 'yyyy-MM-dd HH:mm:ss z' :使用'yyyy-MM-dd HH:mm:ss z'

select parse_datetime('2023-01-31 11:21:33 GMT', 'yyyy-MM-dd HH:mm:ss z')

Output: Output:

_col0 _col0
2023-01-31 11:21:33.000 UTC 2023-01-31 11:21:33.000 UTC

parse_datetime is Java date function which uses JodaTime's DateTimeFormat pattern format which is mostly compatible with java.text.SimpleDateFormat with z matching general timezone . parse_datetimeJava 日期 function ,它使用JodaTime 的 DateTimeFormat 模式格式,它与java.text.SimpleDateFormat大部分兼容, z匹配一般时区

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM