跳至內容
選單
此問題已被標幟
1 回覆
9317 瀏覽次數

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.

頭像
捨棄
最佳答案

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


 

頭像
捨棄
作者

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)

相關帖文 回覆 瀏覽次數 活動
3
6月 25
948
1
7月 23
3620
4
12月 22
9583
2
4月 21
3647
1
10月 18
4994