I am trying to parse some timestamps in python. They look like this:
1334423456 +0200
where obviously the first part is a UNIX timestamp, and the second part the timezone offset in format “+HHMM”/”-HHMM”. I am trying to get this into a python.datetime object.
I can use the first part with datetime.fromtimestamp:
datetime.fromtimestamp(s.split()[0])
but I have no idea how to apply the second part (timezone offset) to it. Any help would be appreciated.
The easiest method is to use the
iso8601module; it includes an (internal) timezone parser that handles almost your format; we need to insert a:to follow make it match ISO 8601 timezones: