Django时区和时区。现在()

2024-06-02 05:01:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下几点设置:-你知道吗

TIME_ZONE = 'Asia/Kolkata'  
USE_I18N = True
USE_L10N = True
USE_TZ = True

另外,我在我的DateTimeField中设置了auto_now = True。但是,保存在UTC的in列中的datetime(即-5:30小时)。你知道吗

我已经按照Asia/Kolkata时区设置了系统日期。还有

>>> from django.utils import timezone
>>> from datetime import datetime
>>>
>>> datetime.now()
datetime.datetime(2019, 7, 13, 17, 40, 1, 505516)  # this is right
>>> timezone.now()
datetime.datetime(2019, 7, 13, 12, 10, 6, 496772, tzinfo=<UTC>)  # this is not what I expect.

为什么在timezone.now()中存在差异,即使TIME_ZONE设置正确??你知道吗


Tags: fromimporttruezonedatetimetimeisuse