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

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
Buang
Jawaban Terbai

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
Buang
Penulis

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)

Post Terkait Replies Tampilan Aktivitas
3
Jun 25
945
1
Jul 23
3618
4
Des 22
9579
2
Apr 21
3643
1
Okt 18
4993