1

I create a django project, but the default timezone is not correct.I have try to find something about how to correct it, but it still doesn't work.So, what should I do?

bobo pei
  • 52
  • 1
  • 10

3 Answers3

1

Have you tried setting the TIME_ZONE in your settings.py file?

Check How to set the timezone in Django? for more info.

If this doesn't solve your problem, could you please include your code?

Sander Vanden Hautte
  • 2,138
  • 3
  • 22
  • 36
1

You toggle everything inyour settings.py Timezones should be activated in your project. That's the default:

USE_TZ = True
TIME_ZONE = <your Timezone>

If you've done this and still face issues, please note:

Django cannot reliably use alternate time zones in a Windows environment. If you’re running Django on Windows, TIME_ZONE must be set to match the system time zone.

ascripter
  • 5,665
  • 12
  • 45
  • 68
  • I use iMac, I find the code `TIME_ZONE =UTC USE_TZ = True `, and I set `TIME_ZONE = Asia/Shanghai`, finally it works correctly.You did me a great favor. – bobo pei Feb 11 '18 at 01:53
0

Setting TIME_ZONE might work if you run the application on your laptop. For production code set TZ environmental variable (for example in the docker) based on where the code is being deployed to keep the times correct.

anishtain4
  • 2,342
  • 2
  • 17
  • 21