我 {{value.time}}
在这个值中有一个变量执行
March 22, 2013, 2:30 a.m
但我想 2:30 a.m
在我的模板文件中删除这个值的(时间)。我怎么能这样做?
将日期作为扩展名
{{ value.time.date }}
>>> from datetime import datetime,date
>>> date_str = 'March 22, 2013, 2:30 a.m'
>>> date_str = date_str.replace('a.m','AM')
>>> formatter_string = "%B %d, %Y, %I:%M %p"
>>> datetime_object = datetime.strptime(date_str, formatter_string)
>>> date_object = datetime_object.date() # date object without '2:30 AM'
>>> date_object
datetime.date(2013, 3, 22)
>>> formatter_string = "%B %d, %Y"
>>> datetime_string = datetime.strftime(date_object, formatter_string)
>>> datetime_string
'March 22, 2013'