Convert local time to UTC using pytz adds DST?

>>> t = datetime.datetime(2016, 11, 27, 14, 46, 0, 0) tz = pytz.timezone('America/Vancouver') utc = tz.localize(t).astimezone(pytz.utc) now = datetime.datetime.utcnow() >>> print t, tz, utc, now 2016-11-27 14:46:00 America/Vancouver 2016-11-27 22:46:00+00:00 2016-10-27 21:49:33.723605 

Why utc == 2016-11-27 22 : 46: 00 + 00: 00 instead of 2016-11-27 21 : 46: 00 + 00: 00

thanks

+6
source share
1 answer

Good, because Vancouver is observing daylight saving time (see this )

Between March 13, 2016 and November 6, Vancouver is UTC-7. After November 6th, he is UTC-8. So, 2:46 p.m. (2:46 p.m.) today (October 27, 2016) still falls into the DST time zone part of the time, and it will be 14 + 7 = 21 (21:46 p.m.) in UTC.

However, on November 27 (the date you convert), Vancouver has already returned to the β€œregular” (not DST) time, UTC-8, so at 14:46 p.m. in Vancouver on November 27, 2016 it is 14 + 8 = 22 (10: 46 PM). In fact, it will be like any date after November 6th.

+4
source

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


All Articles