🛤️ Ruby on Rails - Time
Updated at 2016-01-06 22:47
Config your timezone accordingly in application.rb
.
config.time_zone = "Eastern European Time"
# optional - note it can be only :utc or :local (default is :utc)
config.active_record.default_timezone = :local
Don't use Time.parse
. Use Time.zone.parse
.
# bad
Time.parse("2015-03-02 19:05:37") # => system's time zone.
# good
Time.zone.parse("2015-03-02 19:05:37") # => Mon, 02 Mar 2015 19:05:37 EET +02:00
Don't use Time.now
.
# bad
Time.now # => System time and ignores your configured time zone.
# good
Time.zone.now # => Fri, 12 Mar 2014 22:04:47 EET +02:00
Time.current # => the same thing but shorter.