When I instantiate a datetime object like this:
>>> print(datetime.datetime.now())
2023-09-16 10:30:15.50
I get the correct local time, which is currently around 10:30 AM
.
Why is it like this? Shouldn't it default to UTC time or something?
datetime.datetime.now()
function returns the current local date and time by default. The local time is determined by the system's time zone settings.import datetime
print(datetime.datetime.now(datetime.timezone.utc))