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 6706225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:29:43+00:00 2026-05-26T07:29:43+00:00

I have a rails app where the time zone is being set in application.rb:

  • 0

I have a rails app where the time zone is being set in application.rb:

config.time_zone = 'Pacific Time (US & Canada)'

I want to access this time zone in a controller so that I can convert a UTC time to local time. I have tried numerous things like the following:

@event.start_time = Time.zone.utc_to_local(@event.start_time)

But it doesn’t seem to allow me to call methods on Time.zone. I also tried it using ActionHelper::Time but did not seem to do it. How are these methods accessed from the controllers?

EDIT: I think part of the problem is I was trying to reset @event.start_time. I changed it so that it’s

@event = current_user.events.build(params[:event])
date = Date.parse(params[:event]["start_date"])

utc_start_time = DateTime.civil( date.year.to_i,
                                          date.month.to_i,
                                          date.day.to_i,
                                          params[:event]["start_hour_min(4i)"].to_i,
                                          params[:event]["start_hour_min(5i)"].to_i )

@event.start_time = Time.zone.utc_to_local(utc_start_time)
@event.save

This now saves but only sometimes (havent yet figured out what factors determine it) and is offsetting in the wrong direction. I will edit this as I’m able diagnose whats happening further.

  • 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-26T07:29:44+00:00Added an answer on May 26, 2026 at 7:29 am

    The way Time Zones work is the all times are stored in the DB as UTC. If your times are not in UTC then you will need to convert them in the DB. Then once you set the time zone in config Rails will translate all times to the config’d time automatically. In the example you gave Rails through active record will display:

    @event.local_start_time
    

    You can use this to support time zones based on the user, for example you could setup something like the filter below.

    before_filter :set_user_time_zone
    
    private
    
    def set_user_time_zone
      Time.zone = current_user.time_zone if logged_in?
    end
    

    There is a good screen cast on how time zone support works, you can watch it here.

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

Sidebar

Related Questions

I have a rails app which is localized in multiple languages. Some time for
I have a rails app with a mobile view using jqtouch. If the application
I have a Rails app with the following action: def some_action headers['Access-Control-Allow-Origin'] = 'http://www.example.com'
In my Rails app, I set up my users table to have a string
I have a single Rails 2.2.2 app that I want to 'share' with multiple
In my application I have: config.time_zone = 'Warsaw' A strange issue I have, is
I have been building a large scale rails app and it has come time
In my Rails app I have a has_many_through relation. I want to use the
I have a rails app that I have serving up XML on an infrequent
I have a Rails app that I have successfully tested with Mongrel and Webkit.

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.