Get local timezone in django

后端 未结 9 639
轻奢々
轻奢々 2020-12-04 17:47

I have a mysql DATETIME value that is stored in system time, UTC. I need to convert that to my local timezone in django. Here is what I currently have:

9条回答
  •  日久生厌
    2020-12-04 18:40

    I have came to the same problem. In my settings, I have set the TIME_ZONE, but the time in MySql still UTC time.

    # settings.py
    TIME_ZONE = 'Asia/Shanghai'
    

    Then I found,in settings.py, USE_TZ has be set to False

    USE_TZ = False

    As pointed out by @MagicLAMP, it only works for single time zone site, please check time-zones if your site is international or if daylight savings happen where your site is used.

提交回复
热议问题