日期时间和时区-OpenERP 7 [英] Datetime and Time Zones - OpenERP 7

查看:133
本文介绍了日期时间和时区-OpenERP 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用datetime字段将当前日期保留在模型中,在该字段中,我表示默认为将当前日期作为值.

I'm keeping the current date in a model using a datetime field in which I am indicating default to take the current date as a value.

_defaults = {
        'f_inicio' : lambda *a: datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
    }

假设当前日期为'07/10/2013 17:24:05',则视图中的日期为'07/10/2013 12:24:05'并已在数据库中更正,日期为' 2013/07/10 17:24:05';收集这减去五个小时.用户可以设置时区"America/Bogota",哥伦比亚在该地区(GTM-5:00).但是由于我得到了应该显示的完全不同的值,所以不知道如何正确显示用户.显然,这将哥伦比亚GTM视为"GTM 0".将应该给我的默认日期 create_date 字段默认为'2013-10-07 22:24:05.384'.

Assuming that the current date is '07/10/2013 17:24:05 ', in the view is the date '07/10/2013 12:24:05' and rectified in the database and the date is '07/10/2013 17:24:05'; gather that this subtracting five hours. The user can set the time zone 'America/Bogota', Colombia is in the region (GTM - 5:00). But do not understand how to properly show when the user since I get a totally different value that should show. Apparently this taking as 'GTM 0' the GTM Colombia. Taking the approximate date create_date field that should have given me as default is '2013-10-07 22:24:05.384'.

任何人都不知道可能会发生什么,非常感谢在这个问题上给我带来的疯狂帮助.

Anyone have any idea what may be happening, really appreciate any help on this issue that is driving me crazy.

推荐答案

这过去使我发疯.这是一个真正的简单问题.

This drived me too crazy in the past. This is a real simple issue.

数据库中存储的日期为UTC(GMT-0)时区.假设该人的时区设置为格林尼治标准时间(GMT)-5:00,然后在将值存储到数据库时,日期将加上5个小时(恰好是5个小时,不多一点或少一点),因此我们得到UTC时间为存储到数据库中.现在,当显示相同的内容时,它将检查用户的时区,并发现其格林尼治标准时间5:00,因此数据库时间将减去5(正好是5,不多一点或少一点),并向用户显示.

The date stored in the database is UTC (GMT-0) timezone. Assume that the person is set with timezone GMT - 5:00, then while storing the value to the database, the date will be added with 5 hrs (exactly 5, not little more or little less) and thus we get the UTC time to store into the database. Now when displaying the same it will check for the users timezone and it finds that its GMT - 5:00 so the database time will be subtracted with 5 (again exactly 5, not little more or little less) and displayed the user.

这对于在不同时区使用的系统非常有用.因此,我们的理解是,输入是在存储在UTC(GMT-0)中的用户时区中获取的,并显示到用户的时区中(即使用户查看的时区不同,时间也将精确到他们的时区)

This will be great for system which is used in different timezones. So the understanding is the input is taken in the user's timezone stored in UTC(GMT-0) and displayed to user's timezone (even if the user viewing is in the different timezone the time will be accurate to their timezone)

注意:如果未为用户设置时区,则会考虑浏览器的时区,并将其与右上角的警告图标一起使用

Note: if the user is not set with the timezone the browsers timezone is considered and will be used with the warning icon on the top corner

就是这样.希望这能使您更加清晰!!

That's it. Hope this gives u better clarity!!

这篇关于日期时间和时区-OpenERP 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆