Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:42:35+00:00 2026-05-16T23:42:35+00:00

In config/application.rb I have config.time_zone = ‘UTC’ (without quotes) in the file. I am

  • 0

In config/application.rb I have “config.time_zone = ‘UTC'” (without quotes) in the file. I am assuming this is to make the conversion from the user’s time, which is entered into the view, to UTC, which is stored in the database. My question is, how do I convert the UTC value from the database to the user’s local time to display in the view? I have read that rails takes care of that automatically – how do I tell it to do this?

I have a timezone field in each user’s row in the database, I’m just not sure what to store in there, also. I know about rake time:zones:all – I just don’t know how all of this fits together in rails 3!

Thank you,

sk

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:42:35+00:00Added an answer on May 16, 2026 at 11:42 pm

    When working in multi-zone environment it’s wise to have time zone set to UTC. That’s perfectly valid in your application.rb

    Rails will automatically transform all time to the current time zone, that can be set with

    Time.zone = "some-zone"
    

    What I use is a before_filter in ApplicationController where I set the time zone according to the current user. Then all operations works within this zone and you don’t need to think about it in your controllers/models/views.

    Suppose that you have some model Foo with some datetime field. Then working in the irb console:

    Time.zone = "Prague"
    x = Foo.create(:it_will_happen_at => Time.zone.now)
    x.it_will_happen_at # => Sat, 25 Sep 2010 13:45:46 CEST +02:00 
    
    Time.zone = "London"
    # it is needed to refresh the field after a time zone has changed.
    # In normal situation it'd not be needed, it's just for this console example
    x.reload
    x.it_will_happen_at # => Sat, 25 Sep 2010 12:44:46 BST +01:00 
    

    When you take a look into the DB, you’ll find that value is Sat, 25 Sep 2010 11:45:46 UTC.

    As for the zone value I prefer names of cities as it works smoothly with daylight savings (summer / winter time).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem, my rake file looks like this: require File.expand_path('../config/application', __FILE__) require
I have a problem with rails timezones. application.rb config.time_zone = 'Athens' controller @from =
I have a file located at [application]/config/routing.yml, when I change something in there, the
I have a Web application (with a Web.config file), which will move through the
I have a web application that is deployed with web.config file. Are there any
I have an service application that reads a config file containing a list of
In my application I have: config.time_zone = 'Warsaw' A strange issue I have, is
I have in my application.rb : config.active_record.default_timezone = :local What happens because of this,
I have a config file: application/config/breadcrumbs.php Within the file I have the following configuration
I do NOT have config.active_record.whitelist_attributes = true in application config. And I have attr_protected()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.