Time 错误日期和时间odoo v8

Time 错误日期和时间odoo v8,time,odoo-8,Time,Odoo 8,当我打印报告时,我总是把时间弄错(-1小时),我不知道如何解决这个问题 我的代码中有此函数: def _interpolation_dict(self): t = time.localtime() # Actually, the server is always in UTC. return { 'year': time.strftime('%Y', t), 'month': time.strftime('%m', t), 'day

当我打印报告时,我总是把时间弄错(-1小时),我不知道如何解决这个问题

我的代码中有此函数:

def _interpolation_dict(self):
    t = time.localtime() # Actually, the server is always in UTC.
    return {
        'year': time.strftime('%Y', t),
        'month': time.strftime('%m', t),
        'day': time.strftime('%d', t),
        'y': time.strftime('%y', t),
        'doy': time.strftime('%j', t),
        'woy': time.strftime('%W', t),
        'weekday': time.strftime('%w', t),
        'h24': time.strftime('%H', t),
        'h12': time.strftime('%I', t),
        'min': time.strftime('%M', t),
        'sec': time.strftime('%S', t),
    }

您需要将UTC时区转换为用户时区

您可以使用以下方法来完成

from datetime import datetime
import pytz

time_zone=self.env.user.tz
if time_zone:
    local_now = datetime.now(pytz.timezone(time_zone))
else:
    local_now=datetime.now()
return {
        'year': local_now.strftime('%Y'),
        'month': local_now.strftime('%m'),
        'day': local_now.strftime('%d'),
        'y': local_now.strftime('%y'),
        'doy': local_now.strftime('%j'),
        'woy': local_now.strftime('%W'),
        'weekday': local_now.strftime('%w'),
        'h24': local_now.strftime('%H'),
        'h12': local_now.strftime('%I'),
        'min': local_now.strftime('%M'),
        'sec': local_now.strftime('%S'),
    }    
在上述方法中,我们使用datetime.now()获得UTC时区 之后,使用pytz将UTC时区转换为用户时区 功能

这可能对你有帮助