2016年6月5日星期一,而不是2016年6月5日的DateTimeField [英] getting Monday , june 5 , 2016 instead of June 5 ,2016 using DateTimeField
问题描述
我有一个使用Django的应用程序,我的模型有以下字段:
date = models.DateTimeField(auto_now_add =真的,auto_now = False)
使用我得到这样:2016年6月5日,下午9:16
但我需要一些类似的东西:2016年6月5日,星期一
/ p>
任何帮助将是伟大的
感谢提前
这取决于上下文。在模板中,您可以使用日期模板标签:
< span> {{my_date | date:l,F j,Y}}
或在Python上下文 strftime :
my_date.strftime(%A ,%B%W,%Y)
如果您只需要日期(无时间)你可以考虑使用django的 models.DateField
而不是 models.DateTimeField
I have an app using Django an my my model has the following field:
date = models.DateTimeField(auto_now_add=True,auto_now=False)
Using that I get this: June 5, 2016, 9:16 p.m.
but I need something like : Monday, June 5, 2016
How I can get that??
Any help will be great Thanks in advance
It depends on the context. In a template you can use the date template tags:
<span>{{ my_date|date:"l, F j, Y" }}
or in Python context strftime:
my_date.strftime("%A, %B %W, %Y")
In case you just need the date (without time) you could consider using django's models.DateField
instead of models.DateTimeField
这篇关于2016年6月5日星期一,而不是2016年6月5日的DateTimeField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!