获取当前时区时间
有时候我们默认获取当前时间会出错,我们通常自己写一个方法,然后调用它,下面分享一个当前时区时间的代码:
def get_location_time(self):
"""
获取当前时区时间(带时区)
:return:
"""
now_time = datetime.datetime.utcnow()
tz = self.env.user.tz or 'Asia/Shanghai'
return str(now_time.replace(tzinfo=pytz.timezone(tz)))
然后通过在字段设置默认值。就可以得到正确的时间了。
pay _time = fields.Datetime(string=u’支付时间’,
default=lambda self: self.env[‘yhb.common’].get_location_time())
其中:
yhb.common
:表示方法的_name的值。
快去试试吧。