6

{{value.time}}在这个值中有一个变量执行

March 22, 2013, 2:30 a.m

但我想 2:30 a.m在我的模板文件中删除这个值的(时间)。我怎么能这样做?

4

2 回答 2

9

将日期作为扩展名

{{ value.time.date }}
于 2013-03-22T09:43:46.070 回答
3
>>> 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'
于 2013-03-22T10:53:03.053 回答