django的datetime问题

django的models.py中定义了pub_date = models.DateTimeField('date published')这个字段,存入数据库中的数据格式为:2014-01-09;
我取出来的datetime的格式为:2014-01-09 00:00:00+00:00;
我的页面模板中使用<span class="date">{{ article.pub_date }}</span>。
我希望在页面中显示2014-01-09,
方法1:对取出的时间处理,article.pub_date = article.pub_date.strftime("%Y-%m-%d")
方法2:页面模板更改为,<span class="date">{{ article.pub_date|date:"Y-m-d" }}</span>

参考:http://www.w3cschool.cc/python/att-time-strftime.html
posted @ 2014-09-13 10:15  sandyliang  阅读(820)  评论(0编辑  收藏  举报