【发布时间】:2019-03-05 12:07:26
【问题描述】:
我有一个模型在模型的__str__() 方法中显示一个短字符串
def __str__(self):
return "Scheduled at %s" % (self.date_time.strftime("%B %d %Y %I:%M %p"))
#Output: <Task: Scheduled at September 30 2018 12:30 AM>
# it should have been: <Task: Scheduled at September 29 2018 08:30 PM>
当我转到 Django 管理员 时,我在标题中看到 Task: Scheduled at September 30 2018 12:30 AM 并在输入中填充了正确的TIME_ZONE:20:30:00
settings.py
TIME_ZONE = 'Etc/GMT+4'
USE_I18N = False
USE_L10N = False
USE_TZ = True
他一直以 UTC 时区显示时间,但我在设置中设置了 TIME_ZONE='Etc/GMT+4。
我希望将时间数据以 UTC 格式保存在数据库中,并以 TIME_ZONE 显示,在我的情况下为 Etc/GTM+4
【问题讨论】:
标签: python django datetime pytz django-timezone