August 2018
Intermediate to advanced
366 pages
10h 14m
English
The steps for this recipe are as follows:
import datetime
def asutc(d):
return d.astimezone(datetime.timezone.utc)
>>> now = datetime.datetime.now().replace(
... tzinfo=datetime.timezone(datetime.timedelta(hours=1))
... )
>>> now
datetime.datetime(2018, 3, 22, 0, 49, 45, 198483,
tzinfo=datetime.timezone(datetime.timedelta(0, 3600)))
>>> asutc(now)
datetime.datetime(2018, 3, 21, 23, 49, 49, 742126, tzinfo=datetime.timezone.utc)