0

I want to get the local time, so I tried the following codes in my Django shell.

from django.utils import timezone

now = timezone.localtime(timezone.now())
date = now.date()
time = now.time()
##
from datetime import datetime
now = datetime.now()
>>> print(now)
datetime.datetime(2021, 7, 15, 4, 13, 49, 624395)

In both cases, I got the wrong time, but if I use the same code in my terminal as python code, I get the current and local time.

>>> datetime.now()
datetime.datetime(2021, 7, 15, 8, 22, 50, 316528)
>>> 

Hadi Alizada
  • 21
  • 1
  • 1

0 Answers0