Django source code (as shown in the selected answer) explains the concept of timezone.now()
:
datetime.now()
gives the current time (in your active time zone!) without time zone information ("naive datetime"), whereas ...timezone.now()
always gives the current time in UTC (!) format with information about the time zone.
This is annoying at first sight, yes. They might decide to devote the current time to the active time zone, but they did not. You can use timezone.localtime(timezone.now())
to get what you want:
from django.utils import timezone from datetime import datetime timezone.get_current_timezone()
For beginners and regular users, timezone.localtime(timezone.now())
is probably the most intuitive. Local time that still stores time zone information.
source share