The effect of django.utils.timezone.activate

I have a question regarding the package django.utils.timezone.

I am in the UTC + 7 time zone. Thus, if it is 16:00 local time, it timezone.now()returns 9:00. This is normal.

However, when I do the following:

current_tz = pytz.timezone('Europe/Moscow')  # UTC + 4
timezone.activate(current_tz)

I expect to be timezone.now()back at 12:00 at 16:00 local time, but the exit will remain the same at 9:00.

Does timezone.activate () affect anything at all?

+4
source share
1 answer

timezone.now () explicitly returns UTC time.

After timezone.activate, timezone.localtime (timezone.now ()) returns the desired result.

+1
source

All Articles