I have a list of strings start_date
containing 147 different timestamps 2022-02-05T22:58:59
. I am trying to convert each date/element in the list to an ISO 8601/RFC 3339 format 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']
So far I have tried using the rfc3339
function from library rfc3339
start_date = rfc3339(start_date, utc=True, use_system_timezone=False)
It results in following error TypeError: 'module' object is not callable
Are there any other solutions? Thank you
CodePudding user response:
Based on that error message, you've probably done import rfc3339
, not from rfc3339 import rfc3339
. You can't call the module (as it's telling you).
That said, if all your strings are of the format YYYY-MM-DDTHH:mm:ss
and you want YYYY-MM-DDTHH:mm:ssZ
, why not just...
z_dates = [date "Z" for date in start_date]