问题
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