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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:31:30+00:00 2026-06-07T11:31:30+00:00

I have set the time zone in /config/application.rb , and I expect all times

  • 0

I have set the time zone in /config/application.rb, and I expect all times generated in my app to be in this time zone by default, yet when I create a new DateTime object (using .new), it creates it in GMT. How can I get it to be in my app’s time zone?

config/application.rb

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

irb

DateTime.now
# => Wed, 11 Jul 2012 19:04:56 -0700 

mydate = DateTime.new(2012, 07, 11, 20, 10, 0)
# => Wed, 11 Jul 2012 20:10:00 +0000                    # GMT, but I want PDT

Using in_time_zone doesn’t work because that just converts the GMT time to PDT time, which is the wrong time:

mydate.in_time_zone('Pacific Time (US & Canada)')
# => Wed, 11 Jul 2012 13:10:00 PDT -07:00               # wrong time (I want 20:10)
  • 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-06-07T11:31:32+00:00Added an answer on June 7, 2026 at 11:31 am

    You can use ActiveSupport’s TimeWithZone (Time.zone) object to create and parse dates in the time zone of your application:

    1.9.3p0 :001 > Time.zone.now
     => Wed, 11 Jul 2012 19:47:03 PDT -07:00 
    1.9.3p0 :002 > Time.zone.parse('2012-07-11 21:00')
     => Wed, 11 Jul 2012 21:00:00 PDT -07:00 
    
    • 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 where the time zone is being set in application.rb:
I have a web application that wants you to set a time zone and
I have a set of transactions occurring at specific points in time: CREATE TABLE
I have to print the EST time in my Java application. I had set
i have set the timezone to any time zone that the user have for
I have an app where I set time zones for various cities around the
T-SQL DateTime Question. I have a set of time ranges. During those time ranges
Although I have set pyramid.reload_templates to true e.g. pyramid.reload_templates = true , each time
I have a time_select in which I am trying to set a time value
I have a mysql table field set as time type which stores data in

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.