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

前端 未结 2 1761
被撕碎了的回忆
被撕碎了的回忆 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条回答
  • 2021-01-31 02:13

    See question #2 in the "Usage" section of the Django docs.

    >>> from django.utils import timezone
    >>> timezone.localtime(timezone.now())
    
    0 讨论(0)
  • 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.
    
    0 讨论(0)
提交回复
热议问题