在我的django项目的settings.py文件中,我有这样一行:
TIME_ZONE = 'UTC'
但我想让我的应用程序在UTC+2时区运行,所以我把它改成了
TIME_ZONE = 'UTC+2'
它给出错误ValueError:不正确的时区设置:UTC+2。正确的做法是什么?
谢谢!
在我的django项目的settings.py文件中,我有这样一行:
TIME_ZONE = 'UTC'
但我想让我的应用程序在UTC+2时区运行,所以我把它改成了
TIME_ZONE = 'UTC+2'
它给出错误ValueError:不正确的时区设置:UTC+2。正确的做法是什么?
谢谢!
当前回答
以下是有效的时区列表:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
你可以使用达卡的时区
TIME_ZONE = 'Asia/Dhaka'
UTC+06:00(达卡或阿斯塔纳)
其他回答
以下是有效的时区列表:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
你可以使用
TIME_ZONE = 'Europe/Istanbul'
对于 UTC+02:00
以下是有效的时区列表:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
你可以使用达卡的时区
TIME_ZONE = 'Asia/Dhaka'
UTC+06:00(达卡或阿斯塔纳)
添加Preferred TIME_ZONE并设置USE_TZ为False,如下所示
TIME_ZONE = '亚洲/加尔各答' USE_TZ = False
希望它能起作用。
从tzinfo数据库中选择一个有效的时区。它们倾向于采用例如Africa/Gaborne和US/Eastern的形式
找到与您最近的城市相匹配的城市,或者与您的时区相匹配的城市,然后将TIME_ZONE的值设置为匹配。
Change the TIME_ZONE to your local time zone, and keep USE_TZ as True in 'setting.py': TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = True This will write and store the datetime object as UTC to the backend database. Then use template tag to convert the UTC time in your frontend template as such: <td> {% load tz %} {% get_current_timezone as tz %} {% timezone tz %} {{ message.log_date | time:'H:i:s' }} {% endtimezone %} </td>
或者简洁地使用模板过滤器:
<td>
{% load tz %}
{{ message.log_date | localtime | time:'H:i:s' }}
</td>
您可以在官方文档中查看更多详细信息:默认时区和当前时区 当支持时区时,Django在数据库中存储UTC格式的datetime信息,在内部使用时区感知的datetime对象,并在模板和表单中将它们转换为最终用户的时区。