In Python, how does `datetime.datetime.now ()` an "not know" the datetime object?

Apparently, I should run pytz.UTC.localize(datetime.datetime.now())before comparing the current time with other "naive" time objects.

Why? Does the current time correspond to specific time zones?

+3
source share
1 answer
>>> datetime.datetime.now().utcoffset() is None
True

The function nowreally returns a naive object. It contains the field values ​​for the day and time, which are filled in accordance with the locale settings. That is why a separate one is provided utcnow; which always gives you UTC field values ​​(although it is still naive).

+2
source

All Articles