django's timezone.now does not show the right time

前端 未结 2 1760
被撕碎了的回忆
被撕碎了的回忆 2021-01-31 01:52

My server is in London.

In my settings.py I have:

TIME_ZONE = \'Europe/Moscow\'
USE_TZ = True

But when I do this:

2条回答
  •  梦毁少年i
    2021-01-31 02:14

    from django.utils import timezone
    time = timezone.localtime() 
    

    It will give your local time that whatever your TIME_ZONE set to.

    time = timezone.localtime(timezone.now()) # same result, but it is redundant.
    

提交回复
热议问题