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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:05:40+00:00 2026-05-23T07:05:40+00:00

If I have a time string of the form Wed, 22 Jun 2011 09:43:58

  • 0

If I have a time string of the form "Wed, 22 Jun 2011 09:43:58 +0200" coming from a client, I wish to store it with the time zone preserved. This is important because it’s not just the absolute UTC time that is important but also the timezone.

Time.zone.parse(t) will convert the time to whatever the zone that Time.zone is using at the time, losing the source timezone.

Do I have to manually extract the timezone from the above string or is there an idiomatic way to do this?

  • 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-23T07:05:40+00:00Added an answer on May 23, 2026 at 7:05 am

    A DateTime field can only store ‘YYYY-MM-DD HH:MM:SS’ (MySQL), no Time Zone info.

    You should store the datetime in UTC, and the Timezone in a different field, preferably as an integer specifying the offset from UTC in minutes.

    You can extract the offset like this:

    ruby-1.9.2-p180:001:0>> require 'active_support/all' # included by Rails by default
    # => true
    ruby-1.9.2-p180:002:0>> dt = DateTime.parse "Wed, 22 Jun 2011 09:43:58 +0200"
    # => Wed, 22 Jun 2011 09:43:58 +0200
    ruby-1.9.2-p180:003:0>> dt.utc_offset
    # => 7200
    ruby-1.9.2-p180:004:0>> dt.utc
    # => Wed, 22 Jun 2011 07:43:58 +0000
    

    EDIT:

    And to round trip the excercise

    ruby-1.9.2-p180 :039 > u.utc.new_offset(u.offset)
    => Wed, 22 Jun 2011 09:43:58 +0500 
    ruby-1.9.2-p180 :040 > u
    => Wed, 22 Jun 2011 09:43:58 +0500 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a time stamp of the form 17:16:28 Sep 13, 2011 PDT in
I have a date that's in the form of: Wed Aug 17 2011 09:57:09
I have a textbox on my AJAX form which contains date-time formatted string in
I have two values coming in, a string in the form StartTime YYYY-MM-DD HH:MM:SS
I have a datetime string in the form of a string as: 2011-10-23T08:00:00-07:00 How
From time to time I'll have a string in my project which is simply
How do I check for time for between. suppose I have Time in string
I have a service that give me a date time string in the following
I have the following code: int sec = 62; string str = string.Format(Time: {0:xxx},
I have a string variable containing time in hh:mm:ss format . How to convert

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.