(Django)如何获取月份名称? [英] (Django) how to get month name?
本文介绍了(Django)如何获取月份名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的查询:
I have a query like below:
today = datetime.datetime.now()
month = today.month
print month
并输出:
3
我想显示月份名称如三月。我应该怎么做?
I want to display the month name like "March". What should I do?
推荐答案
使用datetime字符串格式化方法,例如
use the datetime string formatting method, e.g.
>>> today.strftime('%B')
'March'
了解更多信息,完整的格式代码列表,请参阅 python datetime
docs
for more info, and a full list of formatting codes, see the python datetime
docs
这篇关于(Django)如何获取月份名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文