Django template datetime.weekday name

时光毁灭记忆、已成空白 提交于 2021-02-18 22:00:59

问题


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

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