Skip to Content
Menu
This question has been flagged
3 Replies
7252 Views

i want to export sale order to excel, but the date timezone is utc+0. my user is setted timezone to other.

how can i fix it?

Avatar
Discard
Best Answer

Hi,

See a sample code for getting the current time as in users timezone.


# Import the packages
from datetime import datetime
import pytz


user = self.env['res.users'].browse(self.env.uid)
# converting time to users timezone
if user.tz:
tz = pytz.timezone(user.tz) or pytz.utc
time = pytz.utc.localize(datetime.now()).astimezone(tz)
else:
time = datetime.now()


Thanks

Avatar
Discard
Best Answer

odoo 11

from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
from datetime import datetime, timedelta, date
start = (datetime.strptime(self.your_date_time_field, DEFAULT_SERVER_DATETIME_FORMAT) + timedelta(hours=7)).strftime('%d/%m/%Y %H:%M:%S')







Avatar
Discard
Best Answer

If you do not use the export for a re-import, you can change the time in the Excel sheet.

Avatar
Discard