Month: February 2024

Datetimes with Timezones in Python

First, let’s show how the commonly-used plain datetime.datetime.now() gets the local time but does not have a timezone: >>> import datetime >>> now = datetime.datetime.now() >>> type(now) <class ‘datetime.datetime’> >>> now datetime.datetime(2024, 2, 17, 12, 47, 40, 34210) >>> print(now) 2024-02-17 12:47:40.034210 >>> now.tzinfo is None True >>> Let’s add timezone to it, using the […]