How to change default timezone for Active Record in Rails?

How to change default timezone for Active Record in Rails?

Add Comment


  • 3 Answer(s)

    Using Application.rb:

    config.time_zone = 'Eastern Time (US & Canada)'
    config.active_record.default_timezone = :local # Or :utc
    

    Answered on January 12, 2019.
    Add Comment

    Rails  change timezone, but continue to have Active Record save in the database in UTC

    # application.rb
    config.time_zone = 'Eastern Time (US & Canada)'
    

    Rails timezone AND have ActiveRecord:

    # application.rb
    config.time_zone = 'Eastern Time (US & Canada)'
    config.active_record.default_timezone = :local
    

    Note:
    Do not forget to restart your Rails server after modifying application.rb.

    The config.active_record.default_timezone can take only two value:

    • :local converts to the timezone defined in config.time_zone.
    • :utc  converts to UTC.
    Answered on January 12, 2019.
    Add Comment

       They same  config.time_zone = ‘Adelaide’ and config.active_record.default_timezone = :local was the winning combination  during the process.

    Answered on January 12, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.