Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
7345 Weergaven

Have a piece of code in python: now = datetime.datetime.now().strftime("%c")

when I run it in python I get this :


>>> import datetime, time; now = datetime.datetime.now().strftime("%c"); print now

Mon Jun 8 10:52:59 2015

This is correct

However when I run in Odoo (regardless of my timezone) it always shows UTC which is 2 hours behind.

Any advise?

Avatar
Annuleer
Auteur Beste antwoord

Had to look at a lot of code to get this to work and lots of testing but we have a solution:


user_pool = self.pool.get('res.users')

user = user_pool.browse(cr, SUPERUSER_ID, uid)

from_zone = pytz.timezone(user.partner_id.tz) or pytz.utc

to_zone = tz.gettz(str(from_zone))

utc = datetime.datetime.now()

utc = utc.replace(tzinfo=tz.tzutc())

now = datetime.datetime.now(tz.gettz('Europe/Berlin')).strftime('%c')

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
mrt. 15
4427
2
apr. 23
3358
2
dec. 22
14939
1
nov. 21
5066
2
feb. 21
16508