【开发笔记】Odoo13 + Postgresql 10开发中时区/时间处理

来源

在Odoo设计之初,就考虑到适应全球一体化业务模式,默认数据库是以UTC时间存放的;这也是odoo设计优秀的地方。
但在国内实际程序开发中,会存在时区的差异,主要考虑到Odoo后台,即Postgresql数据表中数据存储是按UTC时区时间存储的,这样会出现数据导出相差8小时,带来一些不便。以下提供两种处理方式:

1. 代码设计中处理

from datetime import *


# 获得当前时区时间
current_time = (datetime.today() + timedelta(hours=8)).strftime("%Y%m%d%H%M%S")
print(current_time)
#输出结果: 20200302180020

# 获得当前时区星期几
wd = (datetime.today() + timedelta(hours=8)).strftime('%w')
wds = -1
if wd == '1':
    wds = -3
current_date = (datetime.today() + timedelta(hours=8, days=wds)).strftime("%Y-%m-%d")
print(current_date)
#输出结果: 2020-02-28

# 获得当前时区月份
current_month = current_date[:7]
print(current_month)
#输出结果: 2020-02

# 获得当前时区天
current_today = (datetime.today() + timedelta(hours=8)).strftime("%Y-%m-%d")
print(current_today)
#输出结果: 2020-03-02

# 获得当前时区前一天
current_yesterday = (datetime.today() + timedelta(hours=8, days=-1)).strftime("%Y-%m-%d")
print(current_yesterday)
#输出结果: 2020-03-01

2. 前台用户时区设置处理

设置路径:Odoo前端-设置-用户-【进入用户】-个人设置-语言【Chinese (Simplified) / 简体中文】/ 时区【Asia/Shanghai】。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值