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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:15:09+00:00 2026-06-14T04:15:09+00:00

I have the timezone set. config.time_zone = ‘Mountain Time (US & Canada)’ Creating a

  • 0

I have the timezone set.

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

Creating a Christmas event from the console…

c = Event.new(:title => "Christmas") 

using Time:

c.start = Time.new(2012,12,25)  
=> 2012-12-25 00:00:00 -0700 #has correct offset  
c.end = Time.new(2012,12,25).end_of_day  
=> 2012-12-25 23:59:59 -0700 #same deal  

using DateTime:

c.start = DateTime.new(2012,12,25)  
=> Tue, 25 Dec 2012 00:00:00 +0000 # no offset  
c.end = DateTime.new(2012,12,25).end_of_day  
=> Tue, 25 Dec 2012 23:59:59 +0000 # same  

I’ve carelessly been using DateTime thinking that input was assumed to be in the config.time_zone but there’s no conversion when this gets saved to the db. It’s stored just the same as the return values (formatted for the db).

Using Time is really no big deal but do I need to manually offset anytime I’m using DateTime and want it to be in the correct zone?

  • 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-14T04:15:10+00:00Added an answer on June 14, 2026 at 4:15 am

    Yep. Time.new will intepret parameters as local time in the absence of a specific timezone, and DateTime.new will intepret parameters as UTC in the absence of a specific timezone. As documented. You may want to replace Time.new with Time.local for clarity throughout your code.

    What you can do is use DateTime‘s mixins for Time to invoke Time.local(2012,12,25).to_datetime. But if the year/month/day is coming from a user/browser, then perhaps you should get the user’s/browser’s timezone instead of using your server’s.

    If you need to create a migration to fix existing data in the DB, new_date_time = Time.local(old_date_time.year, old_date_time.mon, old_date_time.mday, old_date_time.hour, old_date_time.min, old_date_time.sec).to_datetime

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

Sidebar

Related Questions

I have the timezone set on the server to BST (British Daylight Savings Time),
i have set the timezone to any time zone that the user have for
I have config.time_zone in environment.rb set to UTC, and my mySQL server returns the
I have set the time zone in /config/application.rb , and I expect all times
I have a requirement where I have to convert timezone from UTC to a
I have set my mysql db: SET time_zone = 'America/Los_Angeles'; and in php date_default_timezone_set('America/Los_Angeles');
I have this entry in my php.ini file: date.timezone = 'Europe/London'; But every time
In my application I have: config.time_zone = 'Warsaw' A strange issue I have, is
I have a weird problem concerning mysql timezone. In my website config file i
I have a rails app where the time zone is being set in application.rb:

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.