开发者

Timezone or Time conflict

开发者 https://www.devze.com 2023-04-08 11:33 出处:网络
I deployed a Rails App but I\'m getting the times wrong on the created_at columns. I go to rails console production and ran Time.now and I get the correct time.

I deployed a Rails App but I'm getting the times wrong on the created_at columns.

I go to rails console production and ran Time.now and I get the correct time.

I logged in to MySQL and ran SELECT NOW(); and I get the correct time.

But when a new record is created into the database I开发者_运维问答 get that it's about 5am when it's really about 1am.

Anybody experience anything similar? How did you fix it?


The problem is that you don't have default time zone set in your application.

you can do it in your environment.rb (Rails 2) or application.rb (Rails 3) file, you can set the default timezone this way:

    config.time_zone = 'Central Time (US & Canada)'  

Reference: http://databasically.com/2010/10/22/what-time-is-it-or-handling-timezones-in-rails/

0

精彩评论

暂无评论...
验证码 换一张
取 消