How to properly use strptime to convert string data from Google Calendar API to datetime object?
Here are two working cases:
from datetime import datetime, timedelta
obj = datetime.strptime('2018-03-01T12:00:00+01:00', '%Y-%m-%dT%H:%M:%S+01:00')
print(obj) # 2018-03-01 12:00:00
obj = datetime.strptime('2018-03-01T12:00:00+0100', '%Y-%m-%dT%H:%M:%S%z')
print(obj) # 2018-03-01 12:00:00+01:00
And one where I have problem.
obj = datetime.strptime('2018-03-01T12:00:00+01:00', '%Y-%m-%dT%H:%M:%S%z')
print(obj) # ERROR
Why according to documentation %z
does not match +01:00
with colon? But only +0100
without colon?
Is there any way to resolve this problem using datetime
?