Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
1304 Tampilan

i have fields.datetime when i input manual and press enter then time auto +7h but i select time on picker datetime then not +7h. Please help me fix it.

Thanks

Avatar
Buang
Jawaban Terbai

Hi,

It depends on the user's preferred TimeZone. Ensure that the user's timezone is correctly set by going to Settings > Users & Companies > Users, selecting the user, and checking the "Timezone" field under the Preferences page.


You have to use ORM methods to convert the datetime data to a different timezone (TZ).


import pytz

from datetime import datetime

from odoo import fields


# Ensure you have the user's timezone set

user_tz = self.env.user.tz or 'UTC'

local_tz = pytz.timezone(user_tz)


# Convert datetime from string to UTC timezone

utc_dt = pytz.utc.localize(datetime.strptime(your_date_or_datetime_info, fields.Datetime.DEFAULT_SERVER_DATETIME_FORMAT))


# Convert UTC datetime to user's local timezone

date_field = utc_dt.astimezone(local_tz).strftime("%d/%m/%Y %H:%M:%S")


Hope it helps

Avatar
Buang