There are two types of datetime objects—time zone-naive and time zone-aware. Time zone-naive objects do not hold time zone information and timezone-aware objects hold time zone information. This recipe demonstrates multiple time zone related operations on datetime objects: creating time zone-naive and time zone-aware objects, adding time zone information to time zone-aware objects, removing time zone information from time zone-naive objects, and comparing time zone-aware and time zone-naive objects.
How to do it…
Execute the following steps for this recipe:
- Import the necessary modules from the Python standard library:
>>> from datetime import datetime
- Create a time zone-naive datetime object. Assign it to now_tz_naive and print it:
>>> now_tz_unaware = datetime.now()
>>> print(now_tz_unaware)
We get the following output. Your output may differ:
2020-08-12 20:55:50.598800
- Print the time zone information of...