Here's what I'm trying to do:
>>> from email.utils import parsedate
>>> tup = parsedate("Fri, 22 Jan 2016 10:15:00 GMT")
>>> tup
(2016, 1, 22, 10, 15, 0, 0, 1, -1)
>>> import datetime
>>> import time
>>> timestamp = time.mktime(tup)
>>> timestamp
1453454100.0
>>> datetime.datetime.utcfromtimestamp(timestamp)
datetime.datetime(2016, 1, 22, 9, 15)
I'm using the email.utils.parsedate
function to parse an RFC 2822 date to a struct_time. This looks correct, the hour part is 10
. Then, I convert it to a timestamp using time.mktime
, and then, I try to get a UTC datetime out of it using datetime.utcfromtimestamp
, but for some odd reason, the hour in the datetime is 9
. I don't really get why.
I'm in UTC+1, so there's probably a conversion to local time happening somewhere, but I have no clue where.