Ruby 2.5 series Ruby on Rails 5.2 series
In Rails, the timezone of the time stamp issued by ActiveRecord is defined in config/application.rb.
# config/application.rb
Rails.application.configure do
config.active_record.default_timezone = :local
# (ActiveRecord::Base.default_timezone = :Synonymous with local)
Omission
end
What this: local refers to is the ruby process timezone.
The ruby process timezone looks at the environment variable TZ
defined in the OS.
In other words, if you don't set this environment variable, ActiveRecord will issue a timestamp with the default UTC.
For example, if you define as follows, created_at and updated_at will be the time in Tokyo.
TZ=Asia/Tokyo
Speaking of time zones set in Rails, I think that there are also the following people.
Rails.application.configure do
config.time_zone = 'Tokyo'
end
This is a setting that allows you to set the time zone acquired by Time.zone
to Tokyo.
You can get the current time in Tokyo by hitting Time.zone.now
on the application.
Recommended Posts