Gediminas Šukys
Gediminas Šukys

Reputation: 7391

Why "created_at" wrong time when saved to database?

When I check time on Rails in my production server

$ rails console production
$ Time.now # good time

On Mysql production

mysql > select now(); # good time

but after I'm saving any record to database, "created_at" and "updated_at" fields are -2 hours from current time. What is wrong here?

I have restarted mysql, nginx after time changes. What can I do next? Is it Rails of Mysql define time for these fields?

Upvotes: 9

Views: 2337

Answers (1)

Brozorec
Brozorec

Reputation: 1183

That's because the timezone your data is saved in the db is UTC. If you want to change it to local, set in application.rb:

config.active_record.default_timezone = :local

and you should declare explicitly your timezone if you haven't yet:

config.time_zone = 'Vilnius'

Upvotes: 10

Related Questions