[英]UTC time 1 Hour Early Rails
I have an issue where time gets saved 1 hour early: 我遇到一个问题,即提前1小时节省了时间:
:time => "6:00AM".to_time
This saves as "13:00 UTC"
when it should be "14:00 UTC"
当它应为"14:00 UTC"
时,它将另存为"13:00 UTC"
"14:00 UTC"
I've set local time to PST: 我已将当地时间设置为PST:
config.time_zone = 'Pacific Time (US & Canada)'
Based on @hd1's explanation: 基于@ hd1的解释:
if Time.zone.now.dst?
:time => "6:00AM".to_time + 1.hour
else
:time => "6:00AM".to_time
end
Please let me know if there's a more direct solution. 请让我知道是否有更直接的解决方案。
It almost looks like you're running into a daylight savings time issue. 看起来您好像遇到了夏令时问题。 The Rails time extensions let you determine your current offset like Time.zone.now.utc_offset, and Time#dst? Rails时间扩展使您可以确定当前的偏移量,例如Time.zone.now.utc_offset和Time#dst?。 tells you if it's Daylight Savings Time with those two you can conditionally subtract the extra hour (3600 hundred seconds). 告诉您这是夏时制,那么您可以有条件地减去额外的小时(3600秒)。 Hope that helps. 希望能有所帮助。 If it doesn't leave a comment and I'd be happy to dig into the rails source code for a solution. 如果它不发表评论,我很乐意深入研究Rails源代码以寻求解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.