Django:使用模板标签将UTC更改为时区感知

时间:2017-11-10 13:43:53

标签: python django django-templates

我有<div class="form-group"> @Html.LabelFor(m => m.LicenseDateOfIssuance, "Date of Issue", new { @class = "col-md-3 control-label required-field" }) <div class="col-md-9"> @Html.EditorFor(m => m.LicenseDateOfIssuance, new { htmlAttributes = new { @class = "form-control DateTimePicker", placeholder = "Date of Issuance", @readonly = "true" } }) </div> </div> <div class="form-group"> @Html.LabelFor(m => m.LicenseDateOfExpiry, "Date of Expiry", new { @class = "col-md-3 control-label required-field", placeholder = "eg 1 Jan 2015" }) <div class="col-md-9"> @Html.EditorFor(m => m.LicenseDateOfExpiry, new { htmlAttributes = new { @class = "form-control DateTimePicker", placeholder = "Date of Expiry", @readonly = "true" } }) </div> </div> 的DateField(),它在utc中。我想将它转换为时区感知对象 我试着写

start_date

它什么都没显示。它只是DateTimeField()的时区吗?如何在DateField()上使用它。

1 个答案:

答案 0 :(得分:0)

是的,不幸的是,这仅适用于datetime个对象(s。https://github.com/django/django/blob/abaf0ab4a444977dc8ac07b9b63256814c352245/django/templatetags/tz.py#L46

据我所知,没有真正的方法可以使date对象时区感知。您可以将date对象转换为datetime但是(s。https://stackoverflow.com/a/1937636/246028

如果您通过了解日期时区来告诉我们您要实现的目标,我可以尝试修改我的答案。