win32timezone.TimeZoneInfo.local

local()

Returns the local time zone as defined by the operating system in the registry.

Comments

Now one can compare the results of the two offset aware values

>>> (now_UTC - now_local) < datetime.timedelta(seconds = 5)

True

Or use the newer `datetime.timezone.utc`

>>> now_UTC = datetime.datetime.now(datetime.timezone.utc)

>>> (now_UTC - now_local) < datetime.timedelta(seconds = 5)

True

>>> localTZ = TimeZoneInfo.local() >>> now_local = datetime.datetime.now(localTZ) >>> now_UTC = datetime.datetime.utcnow() # deprecated >>> (now_UTC - now_local) < datetime.timedelta(seconds = 5) Traceback (most recent call last): ... TypeError: can't subtract offset-naive and offset-aware datetimes

>>> now_UTC = now_UTC.replace(tzinfo = TimeZoneInfo('GMT Standard Time', True))