Python 如何在 Django 中添加印度标准时间 (IST)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21855357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add Indian Standard Time (IST) in Django?
提问by Alok
We want to get the current time in India in our Django project. In settings.py, UTC is there by default. How do we change it to IST?
我们想在我们的 Django 项目中获取印度的当前时间。在 settings.py 中,默认情况下是 UTC。我们如何将其更改为 IST?
采纳答案by Jon
Change the field TIME_ZONEin the settings.py.
For the Indian standard time you will need:
更改字段TIME_ZONE中settings.py。对于印度标准时间,您需要:
TIME_ZONE = 'Asia/Kolkata'
For more information about the TIME_ZONE in Django you can see: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
有关 Django 中 TIME_ZONE 的更多信息,您可以查看:https: //docs.djangoproject.com/en/dev/ref/settings/#time-zone
回答by Jitesh Nair
check django_timezones! this may help others too it consists of all other timezones for references
检查django_timezones!这也可能对其他人有帮助 它包含所有其他时区以供参考
回答by techNikunj
You may try setting it UTC+05:30i.e Indian Time Zone
您可以尝试设置它,UTC+05:30即印度时区
回答by Nandha
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
The above settings should work
以上设置应该可以工作
回答by Kishore Bhosale
Modify setting.py and change the time zone to TIME_ZONE = 'Asia/Kolkata'
修改 setting.py 将时区改为TIME_ZONE = 'Asia/Kolkata'
回答by Ashish Gupta
Use Below settings its worked for me. TIME_ZONE = 'Asia/Kolkata'
使用以下设置对我有用。TIME_ZONE = '亚洲/加尔各答'
USE_I18N = True
USE_I18N = 真
USE_L10N = True
USE_L10N = 真
USE_TZ = False
USE_TZ = 错误
回答by Naveen Chand Pandey
Keep TIME_ZONE= 'Asia/Kolkata' in settings.py file and restart the service from where you are accessing the timezone (server or shell). In my case, I restarted the python shell in which I was working and it worked fine for me.
在 settings.py 文件中保留TIME_ZONE= 'Asia/Kolkata' 并从您访问时区的位置(服务器或外壳程序)重新启动服务。就我而言,我重新启动了我工作的 python shell,它对我来说很好用。
回答by roshan172
Simple Change TIME ZONE from 'UTC' to 'Asia/Kolkata' remember K and A is Capital here.
将 TIME ZONE 从 'UTC' 简单地更改为 'Asia/Kolkata' 记住 K 和 A 是这里的首都。
回答by Thrilok Kumar Pallaki
Adding to Jon Answer, If timezone.now()still not working after changing the TIME_ZONE='Asia/Kolkata'.
添加到 Jon Answer,如果timezone.now()更改TIME_ZONE='Asia/Kolkata'.
Instead of timezone.now()you can use timezone.localtime().
而不是timezone.now()您可以使用timezone.localtime().
Hope it solves.. :)
希望它解决.. :)
回答by manoj pali
All the solutions given above are working.
上面给出的所有解决方案都有效。
see the code i have used to get my timezone. my timezone is Indian standard time zone.
查看我用来获取时区的代码。我的时区是印度标准时区。
https://docs.djangoproject.com/en/3.0/topics/i18n/
https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True

