如何更改django datetime格式输出? [英] How to change django datetime format output?
问题描述
< ul>
< li> {{sale.validity}}< / li>
< / ul>
,我收到的输出格式为:
2012年7月18日午夜
我真的想改变输出要以数字形式显示日期 - 年份,例如上述将更改为:
18-07-2012
有人可以指出我正确的方向吗?
根据 Django docs 您可以使用日期
过滤器格式化日期:
{{ sale.validity | date:dmY}}
此外,您还可以设置 DATE_FORMAT (或DATETIME_FORMAT)设置,以设置项目范围的默认值,以显示此类值如果 USE_L10N
为False。如果是这样,您可以查看格式本地化文档。
I have a datetime object. This is my template file:
<ul>
<li>{{ sale.validity }}</li>
</ul>
and the output i'm getting is in the format:
July 18, 2012, midnight
I would really like to change the output to be numerical in the format: day-month-year so for example the above would be changed to:
18-07-2012
Can someone point me out to the right direction on this?
Per Django docs, you can use a date
filter to format date:
{{ sale.validity|date:"d-m-Y"}}
Additionally, you can also set DATE_FORMAT (or DATETIME_FORMAT) setting to set a project-wide default for displaying such values if USE_L10N
is False. If it's true, you'll want to have a look at this documentation on format localization.
这篇关于如何更改django datetime格式输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!