简体   繁体   English

created_at和updated_at另存为明天

[英]created_at and updated_at saving as tomorrow

When objects are created in our Rails app, it's saving in the Postgres DB 7 hours ahead of our time (PDT). 在我们的Rails应用程序中创建对象时,它比我们的时间(PDT)提前7个小时保存在Postgres DB中。 Looks like it's saving everything to UTC. 看起来它正在将所有内容保存到UTC。 This really screws up analytic graphs, ect. 这确实搞砸了分析图,等等。

I have these set in application.rb 我在application.rb中设置了这些

config.time_zone = 'Pacific Time (US & Canada)'
config.active_record.default_timezone = :local

How can I get everything to save/timestamp to the PDT timezone? 如何获取所有要保存/时间戳到PDT时区的内容?

It is (probably) being saved at the timezone of your server, and is independent of your code. 它(可能)保存在服务器的时区,并且独立于代码。 IE, it's your database setting the created_at/updated_at date time (which is defaulting to UTC) IE,这是您的数据库,它设置了created_at / updated_at日期时间(默认为UTC)

What you need to do is make your analytics work with UTC and translate to PDT, not vice versa. 您需要做的是使您的分析与UTC一起使用并转换为PDT,反之亦然。 That gives you a solution that is totally independent of where you are hosted, daylight savings time changes, where your users are, etc. 这为您提供了一个完全独立于您的托管位置,夏令时更改,用户所在位置等的解决方案。

Consider the simple case of if you have users in multiple time zones. 考虑一个简单的情况,如果您有多个时区的用户。 Someone in EST will hate you west coast PDT people 'cause they always have to translate it ;) EST的某个人会讨厌您西海岸的PDT人员,因为他们总是不得不翻译它;

All in all, use and work with UTC - it's... Universal! 总之,与UTC一起使用和使用-这是...通用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM