Get local timezone in django

后端 未结 9 643
轻奢々
轻奢々 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:34

    I personally would advice against using a TIME_ZONE setting other than UTC. I remember having problems with this in the past, be it that the database was operating in a different timezone (saving values in a different timezone) than the Django backend was using. That meant a lot of hassle to compare the times, changing them forth and back depending on what you are doing.

    A good practice is usually to use one timezone in the backend (lets say UTC) and convert the time in the frontend to the users timezone you are serving.

提交回复
热议问题