I need to deal with python with strings representing iso8601 timestamps.
Therefore, the timestamp line is as follows:
timestamp = "2011-08-18T10:29:47+03:00"
I am currently converting them to python using:
timestamp = timestamp[:-6]
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S")
But in this way I lose all the time zone information. I saw many examples here about so about timestamps and python, unfortunately, no one saved the time zone, but simply restored the time zone delay using:
delay = timestamp[-6:]
I also tried:
timestamp = "2011-08-18T10:29:47+03:00"
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S%z")
but he returned
ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S%z'
Can you give some idea?
source
share