问题
Is there a way to display the weekday of a datetime object in a template as the actual name of the weekday? Basically I want it to print Friday
instead of 5
.
回答1:
See the documentation for the built-in date filter. From there you'll see you need to use:
l Day of the week, textual, long. 'Friday'
回答2:
For clarity's sake, the template tag format character "l" (lower-case "L") can be used in the Django template like so:
{{ object.some_date_field | date:"l" }}
Django 1.8.2
回答3:
You can also use:
import datetime
today = datetime.datetime.today()
print(today.strftime('%A'))
来源:https://stackoverflow.com/questions/10455518/django-template-datetime-weekday-name