<span t-field="o.date_order"/>
其输出为:
2017-11-04 09:48:35
但是我怎样才能得到这样的输出:
2017/04/11 09:48
试试这个
<span t-field="o.date_order" t-field-options='{"format": "MM dd y h:mm a"}'/>
你好艾斯瓦娅,
试试下面的代码,
1. 使用模板,
如果您的o.date_order
字段返回此格式类型,10/10/2017 10:10 AM
带有 AM/PM 的日期时间,请使用以下代码,否则会出现错误。
<td>
Order Date:
<t t-esc="time.strftime('%d/%m/%Y %H:%M %a',time.strptime(o.date_order,'%d/%m/%Y %H:%M %a'))" />
</td>
2. 你也可以在 python 中使用创建函数,
如果您有多个日期字段,请使用相同或不同的日期格式,因此 python 函数的使用会更好,因为可以提高代码的可重用性。
1.首先你的 report.py 文件里面写下面的代码,
def __init__(self, cr, uid, name, context=None):
super(class_name, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'format_date':self.format_date
})
def format_date(self,date):
if date:
return str(datetime.strptime(o.date_order, '%d/%m/%Y %H:%M %a').strftime('%d/%m/%Y %H:%M %a'))
2.在下面写代码的第二个report_view_template.xml文件,
<td>
Order Date:
<t t-esc="format_date(o.date_order)" />
</td>
我希望我的回答对您有所帮助。如果有任何疑问,请发表评论。