如何更改默认的 Django 日期模板格式? [英] How can I change the default Django date template format?
本文介绍了如何更改默认的 Django 日期模板格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中有 ISO 8601 格式的日期,%Y-%m-%d
.但是,当日期传递给模板时,它会以类似于 Oct.2011 年 16 月 16 日
.
I have dates in ISO 8601 format in the database, %Y-%m-%d
. However, when the date is passed on to the template, it comes out as something like Oct. 16, 2011
.
有没有一种方法可以将格式处理为我想要的任何格式?
Is there a way that I can manipulate the format to whatever I want?
推荐答案
在你的模板中,你可以使用 Django 的 date
过滤器.例如:
Within your template, you can use Django's date
filter. E.g.:
<p>Birthday: {{ birthday|date:"M d, Y" }}</p>
给出:
生日:1983 年 1 月 29 日
Birthday: Jan 29, 1983
日期过滤器文档中的更多格式示例.
这篇关于如何更改默认的 Django 日期模板格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文