İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
9307 Görünümler

Hello,

I am storing a datetime field by converting from string to datetime using datetime package. It's getting saved properly in database with given values. But when I use that field openerp views I get time mismatch.

datetime.strptime(start_date,'%Y-%m-%d %H:%M:%S') 

" 2014-09-18 00:00:00" # saved datetime in database

In browser(views) its showing  09/18/2014 05:30:00

Can anybody tell how to stop this time conversion.

Avatar
Vazgeç
En İyi Yanıt

This is probably due to the Timezone you selected for the related user (Time zone India: GMT + 5.30).

  1. From this LINK (response from Fabien Pinckaers)

    • Data are stored in the database in UTC (not depending on the timezone of your users)

      When the client receives the data, it translates it according to the timezone of the user which is on the global context that comes from the user preferences (so, the date/time you see on the screen is not the same than the one in the database)

      The client sends back the new dates to the server under the UTC format


 

Avatar
Vazgeç
Üretici

Thanks Bara, I fixed that issue by converting local to UTC timezone. user_time_zone = context.get('tz', False) # can be fetched form logged in user if it is set local = pytz.timezone (user_time_zone) start_date = local.localize(start_date, is_dst=None) # start_date is a naive datetime start_date = start_date.astimezone(pytz.utc)

İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Haz 25
945
1
Tem 23
3618
4
Ara 22
9577
2
Nis 21
3641
1
Eki 18
4992