Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord timezone without rails

I am using ActiveRecord in a non-rails project. In rails I can do:

 config.time_zone = 'Eastern Time (US & Canada)'
 config.active_record.default_timezone = 'Eastern Time (US & Canada)'

But if I am not using rails, how can I set the timezone?

like image 492
0xSina Avatar asked Jul 15 '13 07:07

0xSina


People also ask

Can you use ActiveRecord without rails?

One of the primary aspects of ActiveRecord is that there is very little to no configuration needed. It follow convention over configuration. ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.

How do you get the time zone in Ruby?

Ruby | Time zone() functionTime#zone() : zone() is a Time class method which returns the name of the time zone used for time like “UTC”, “GMT”.


2 Answers

ActiveRecord::Base.default_timezone = 'Eastern Time (US & Canada)'
like image 153
Mike Li Avatar answered Oct 02 '22 22:10

Mike Li


ActiveRecord::Base.default_timezone = :local

also works for me.

like image 42
ohho Avatar answered Oct 02 '22 23:10

ohho