fix 时区问题 and common

This commit is contained in:
ivan deng
2021-03-23 00:23:10 +08:00
parent e5c9cb8912
commit 5f3b900bf0
3 changed files with 8 additions and 6 deletions

View File

@@ -24,10 +24,12 @@ class Base(models.AbstractModel):
"""
if not value:
return value
# 默认中国时区
user_tz = pytz.timezone(self.env.user.tz or 'Etc/GMT+8')
dt_local = pytz.utc.localize(value).astimezone(user_tz)
return dt_local.strftime(return_format)
if isinstance(value, datetime):
value = value.strftime(return_format)
dt = datetime.strptime(value, return_format)
pytz_timezone = pytz.timezone(self.env.user.tz or 'Etc/GMT-8')
dt = dt.replace(tzinfo=pytz.timezone('UTC'))
return dt.astimezone(pytz_timezone).strftime(return_format)
def _app_dt2utc(self, value, return_format=DEFAULT_SERVER_DATETIME_FORMAT):
"""