Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
7346 มุมมอง

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?

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 15
4427
2
เม.ย. 23
3359
Selecting items for one2many relation แก้ไขแล้ว
2
ธ.ค. 22
14940
1
พ.ย. 21
5067
2
ก.พ. 21
16508