In Django, how to display times with lowercase am/pm in templates?

杀马特。学长 韩版系。学妹 提交于 2020-12-29 05:54:19

问题


Django's date/time formats have a code for displaying the am/pm part of times as either:

a.m.

or

AM

but not as:

am

i.e. lowercase without periods.

How do you render times with lowercase am/pm?

NOTE: I thought of the answer while typing in this question, so I figured instead of scrapping it I'd share my answer in case it's helpful to someone else.


回答1:


Use the lower template tag with the time formatting tag, e.g.

{{object.time|time:"g:iA"|lower}}

renders as

12:30pm

compared to

{{object.time|time:"g:iA"}}

which renders as

12:30PM

Note simply using the lower filter on a time object without the explicit time format filter doesn't work. But you can use the default time format, e.g.

{{object.time|time|lower}}


来源:https://stackoverflow.com/questions/12218620/in-django-how-to-display-times-with-lowercase-am-pm-in-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!