I am getting timestamps from a REST server which creates them using datetime.str()
. This gives me a timestamp that looks like: '2018-02-21 10:40:35+00:00'
. However, datetime.strptime
only supports %z
which requires the trailing timezone offset to be in the form +/-nnnn
with no colon. The exact error looks like:
In[16]: str(dt)
Out[16]: '2018-02-21 10:40:35+00:00'
In[17]: datetime.strptime(str(dt), "%Y-%m-%d %H:%M:%S%z")
ValueError: time data '2018-02-21 10:40:35+00:00' does not match format '%Y-%m-%d %H:%M:%S%z'
Is there a strptime
flag that will parse the trailing "+00:00"
as-is, or do I need to resort to str.rpartition
tricks before calling strptime
?