Rails 时区和夏令时 [英] Rails timezone and Daylight saving time
问题描述
有一段时间我试图了解这个时区时间是如何工作的,我有一个问题:
for a while I´m trying to understand how this timezone times will work, and I had a question:
今天在我的国家/地区,我们处于夏令时 (GMT-2).所以我的应用程序的用户输入一个时间,比如上午 11:00 并发布表单.据我所知,rails 会将这个日期转换为 UTC 并保存在数据库中(在我的例子中是 mysql),例如:01:00PM UTC.
Today in my country, we are in Daylight saving time (GMT-2). So the user of my application enter a time, like 11:00AM and post the form. Far as I know, rails will convert this date to UTC and save in the database (mysql in my case), like: 01:00PM UTC.
当我恢复该记录时,我必须转换为当地时间才能显示.好吗?
When I recover that record, I had to convert to local time to display. Ok?
我的问题是,让我们假设这个日期/时间代表未来的日期/时间,当我的国家从夏令时(GMT-3)出来时.Rails 会保存 01:00PM UTC?今天,在夏令时,当地时间如何?未来,这个当地时间会怎样?
My question is, lets suppose that this date/time represents a date/time in future, when my country gets out from summer time (GMT-3). Rails will save 01:00PM UTC? Today, in Daylight saving time, how will be the local time? And in the future, how will be this local time?
基本上,我总是需要在上午 11:00 向用户显示.
Basically, I always need to display to user 11:00AM.
谢谢.
推荐答案
7 个月后您提出要求,但也许 skip_time_zone_conversion_for_attributes=
会有所帮助 - 它告诉 AcitveRecord 在存储或检索时不要转换时区.请参阅 ActiveRecord Timestamp 显示示例:
7 months after you asked, but perhaps skip_time_zone_conversion_for_attributes=
will help - it tells AcitveRecord not to convert timezones on storage or retrieval. See ActiveRecord Timestamp which shows the example:
class Topic < ActiveRecord::Base
self.skip_time_zone_conversion_for_attributes = [:written_on]
end
这篇关于Rails 时区和夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!