跳至內容
選單
此問題已被標幟
2 回覆
5340 瀏覽次數

Hello,

I'm creating a script that makes XMLRPC queries on the POS orders (using search_read), and I need to retrieve the date and time the orders were created. However the query is bringing the datetimes in UTC. Is there a way to request them in a specific timezone?

頭像
捨棄
最佳答案

Hi Hugo,

You Can't but you can convert it by using following code

import pytz

local = pytz.timezone(self.env.user.tz)
naive = datetime.datetime.strptime(Your UTC Time, "%Y-%m-%d %H:%M:%S")
local_dt = local.localize(naive, is_dst=None)
utc_dt = local_dt.astimezone(pytz.utc)
print(utc_dt.strftime("%Y-%m-%d %H:%M:%S"))

Thanks

頭像
捨棄
最佳答案

use can use context_timestamp to convert datetime to user timezone like 

meet_date = fields.Datetime.from_string(self.meeting_date)
meeting_usertime = fields.Datetime.to_string(fields.Datetime.context_timestamp(self, meet_date))


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
7月 25
3022
1
10月 24
2209
2
7月 24
15869
1
4月 24
2262
0
9月 23
1755