August 2018
Intermediate to advanced
366 pages
10h 14m
English
All Python datetimes, by default, come without any time zone specified, but by setting tzinfo, we can make them aware of the time zone they refer to.
If we just grab our current time (datetime.datetime.now()), there is no easy way for us to know from within our software which time zone we are grabbing the time from. The only time zone we can always rely on is UTC, for that reason. Whenever retrieving the current time, it's best always to rely on datetime.datetime.utcnow().
Once we have a date for UTC, as we know it's actually for the UTC time zone, we can easily attach the datetime.timezone.utc time zone (the only one that Python provides out of the box) and make it time-zone-aware.
The now function does that: it grabs the ...