Datetime ignores tzinfo?

Maybe I misunderstand the purpose of tzinfo, but I have a datetime object. dtI managed to get into this form:

datetime.datetime(2017, 7, 2, 20, 0, tzinfo=tzoffset('PDT', -7))

I am trying to submit the indicated date from July 2, 2017, 20:00 PDT.

Now I would like to convert this time to UTC, but when I do this, it displays the UTC timestamp for July 2nd 2017 20:00 UTC, it does not apply the difference of 7 hours.

For instance:

>>> dt.timestamp()
1499025607.0

What is it: Sunday, July 2, 2017 8:00:07 PM

Besides

>>> dt.isoformat()
'2017-07-02T20:00:00-00:00:07'

I tried

>>> dt.astimezone(pytz.UTC).timestamp()
1499025607.0

Please note that the same timestamps as dt.timestamp()

+4
source share
1 answer

According to dateutil docs, your function parameter is tzoffset()incorrect.

tzinfo=dateutil.tz.tzoffset('PDT', -7)

creates a time zone with an offset of 7 seconds.

tzinfo=dateutil.tz.tzoffset('PDT', -7*60*60)

creates a time zone with an offset of 7 hours.

+2

Source: https://habr.com/ru/post/1680667/


All Articles