Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
5365 Weergaven

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?

Avatar
Annuleer
Beste antwoord

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

Avatar
Annuleer
Beste antwoord

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))


Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
jul. 25
3055
1
okt. 24
2229
2
jul. 24
15917
1
apr. 24
2280
0
sep. 23
1792