将字符串列表转换为 ISO 8601/RFC 3339 格式

convert list of string to ISO 8601/RFC 3339 format

我有一个字符串列表 start_date,其中包含 147 个不同的时间戳 2022-02-05T22:58:59。我正在尝试将列表中的每个 date/element 转换为 ISO 8601/RFC 3339 格式 YYYY-MM-DDTHH:mm:ssZ.

print(start_date)
['2022-02-05T22:58:59', '2022-01-27T22:58:59', '2022-01-27T22:58:59', '2022-01-25T22:58:59', '2022-01-22T22:58:59', '2022-01-21T22:58:59', '2022-01-15T22:58:59', '2022-01-11T22:58:59', '2022-01-09T22:58:59', '2021-12-29T22:58:59', '2021-12-15T22:58:59', '2021-11-26T22:58:59', '2021-11-24T22:58:59', '2021-11-05T22:58:59', '2021-10-24T22:58:59', '2021-10-14T22:58:59', '2021-10-09T22:58:59', '2021-09-29T22:58:59', '2021-09-18T22:58:59', '2021-09-16T22:58:59', '2021-09-12T22:58:59', '2021-08-29T22:58:59', '2021-08-28T22:58:59', '2021-08-27T22:58:59', '2021-08-22T22:58:59', '2021-08-14T22:58:59', '2021-08-12T22:58:59', '2021-08-06T22:58:59', '2021-08-04T22:58:59', '2021-07-28T22:58:59', '2021-07-28T22:58:59', '2021-07-22T22:58:59', '2021-07-16T22:58:59', '2021-07-09T22:58:59', '2021-07-07T22:58:59', '2021-07-07T22:58:59', '2021-07-02T22:58:59', '2021-06-30T22:58:59', '2021-06-25T22:58:59', '2021-06-12T22:58:59', '2021-06-10T22:58:59', '2021-06-09T22:58:59', '2021-06-03T22:58:59', '2021-05-27T22:58:59', '2021-05-09T22:58:59', '2021-05-06T22:58:59', '2021-04-30T22:58:59', '2021-04-13T22:58:59', '2021-04-10T22:58:59', '2021-04-07T22:58:59', '2021-03-28T22:58:59', '2021-03-25T22:58:59', '2021-03-18T22:58:59', '2021-03-12T22:58:59', '2021-03-10T22:58:59', '2021-03-06T22:58:59', '2021-03-05T22:58:59', '2021-02-16T22:58:59', '2021-02-10T22:58:59', '2021-02-05T22:58:59', '2021-01-02T22:58:59', '2020-12-04T22:58:59', '2020-07-29T22:58:59', '2020-07-01T22:58:59', '2020-06-24T22:58:59', '2020-06-06T22:58:59', '2020-06-05T22:58:59', '2020-06-03T22:58:59', '2020-05-30T22:58:59', '2020-05-29T22:58:59', '2020-05-28T22:58:59', '2020-05-23T22:58:59', '2020-05-22T22:58:59', '2020-05-21T22:58:59', '2020-05-16T22:58:59', '2020-05-14T22:58:59', '2020-04-29T22:58:59', '2020-04-23T22:58:59', '2020-04-22T22:58:59', '2020-04-12T22:58:59', '2020-04-10T22:58:59', '2020-04-01T22:58:59', '2020-04-01T22:58:59', '2020-03-20T22:58:59', '2020-03-06T22:58:59', '2020-02-28T22:58:59', '2020-02-16T22:58:59', '2020-02-15T22:58:59', '2020-02-08T22:58:59', '2020-02-06T22:58:59', '2020-02-05T22:58:59', '2020-01-30T22:58:59', '2020-01-29T22:58:59', '2020-01-18T22:58:59', '2020-01-17T22:58:59', '2020-01-11T22:58:59', '2020-01-10T22:58:59', '2020-01-10T22:58:59', '2020-01-09T22:58:59', '2020-01-03T22:58:59', '2019-12-14T22:58:59', '2019-12-12T22:58:59', '2019-12-06T22:58:59', '2019-11-28T22:58:59', '2019-11-20T22:58:59', '2019-11-15T22:58:59', '2019-11-09T22:58:59', '2019-10-23T22:58:59', '2019-10-10T22:58:59', '2019-10-02T22:58:59', '2019-09-21T22:58:59', '2019-09-18T22:58:59', '2019-09-14T22:58:59', '2019-09-13T22:58:59', '2019-09-06T22:58:59', '2019-08-31T22:58:59', '2019-07-26T22:58:59', '2019-07-24T22:58:59', '2019-06-27T22:58:59', '2019-06-20T22:58:59', '2019-06-06T22:58:59', '2019-05-29T22:58:59', '2019-05-15T22:58:59', '2019-05-08T22:58:59', '2019-05-03T22:58:59', '2019-05-01T22:58:59', '2019-04-27T22:58:59', '2019-04-24T22:58:59', '2019-04-18T22:58:59', '2019-04-13T22:58:59', '2019-04-06T22:58:59', '2019-03-22T22:58:59', '2019-03-21T22:58:59', '2019-03-20T22:58:59', '2019-03-07T22:58:59', '2019-03-02T22:58:59', '2019-02-16T22:58:59', '2019-01-26T22:58:59', '2019-01-23T22:58:59', '2019-01-10T22:58:59', '2019-01-09T22:58:59', '2019-01-05T22:58:59', '2018-12-14T22:58:59', '2018-12-06T22:58:59', '2018-11-29T22:58:59', '2018-11-23T22:58:59', '2018-11-21T22:58:59']

到目前为止,我已尝试使用库 rfc3339

中的 rfc3339 函数

start_date = rfc3339(start_date, utc=True, use_system_timezone=False) 它导致以下错误 TypeError: 'module' object is not callable

还有其他解决办法吗?谢谢

根据该错误消息,您可能已完成 import rfc3339,而不是 from rfc3339 import rfc3339。您不能调用该模块(正如它告诉您的那样)。

就是说,如果您所有的字符串都是 YYYY-MM-DDTHH:mm:ss 格式并且您想要 YYYY-MM-DDTHH:mm:ssZ,为什么不直接...

z_dates = [date + "Z" for date in start_date]