Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 831
Gediminas Avatar asked Nov 11 '15 10:11

Gediminas


1 Answers

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'
like image 116
Brozorec Avatar answered Oct 31 '22 21:10

Brozorec