1

{{ post.pub_date|localize }}当我在 Django 模板中显示本地化日期 ( ) 时,如何摆脱小时、分钟和秒?

如果我只使用普通日期(类似post.pub_date|date:"d m Y"),我只能显示日、月和年(而不是小时、分钟和 s)。使用本地化过滤器,我似乎无法控制我显示的内容。

作为最后的手段,我在发送帖子之前已将日期时间对象转换为视图中的日期对象,但这需要更多的工作(我在帖子列表中循环)。

谢谢。

4

1 回答 1

0

Django has built-in support for localized dateformatting; it's just disabled by default. Check out the official docs for more information, but the short answer is that you just set USE_L10N=True in your settings.py.

于 2013-03-13T19:22:08.853 回答