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

  • Home
  • SEARCH
  • 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 8437175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:21:42+00:00 2026-06-10T07:21:42+00:00

Given a hash containing time and day, how do I create a time object

  • 0

Given a hash containing time and day, how do I create a time object that is UTC when the hash is some other time zone?

For example, my User is EST and specifies “15:04 8/25/2012” (via a select_datetime in a view) so the time is implicitly EST.

When they submit the form, time_hash = {“day”=>”25”, “month”=>”8”, “year”=>”2012”, “hour”=>”15”, “minute”=>”04”}

If I set

the_time = Time.local params[:date][:year], params[:date][:month], params[:date][:day], params[:date][:hour], params[:date][:minute]

it creates a time object that is 15:04 8/25/2012 — BUT in the SERVER’s local time (Pacific), not the User’s local time (Eastern).

Note: I DO have Time.zone set to Eastern earlier in the same method, so I thought Time.local would interpret the hash as Eastern time, but it doesn’t. I also tried Time.zone.local but that throws an error.

  • 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-10T07:21:44+00:00Added an answer on June 10, 2026 at 7:21 am
    Time.zone.local
    

    should work fine. It’s a little picker than Time.local and will only accept integers as its arguments, whereas Time.local doesn’t mind strings. Sprinkle some calls to to_i in there and you should be ok.

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

Sidebar

Related Questions

Given a string how to create a unique identifier / hash for that string
Given this hash that comes though :params positions=>{ 1=>{x=>50, y=>30}, 2=>{x=>22, y=>53}, 3=>{x=>68, y=>35}
I've been looking for a way to hash a given string in C# that
Can some one explain Given a hash table array of size N=11., and using
I'm building a small app that calculate hash from any given file to multiple
Given a hash that contains function names like find_by_user, find_by_id, ... I want to
In C# Given a hash table like {id:'1', name:'foo'} How can I dynamically create
I'm looking for a function that will generate an alphanumeric hash. Given a source
I have a method that is given a particular options hash like this def
I have a function that returns a hash, given certain parameters: build_message = function(from,

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.