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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:42:00+00:00 2026-05-23T12:42:00+00:00

When I use a datetime_select in my form, Rails will correctly adjust the timezone

  • 0

When I use a datetime_select in my form, Rails will correctly adjust the timezone of the datetime data (as per my config.time_zone setting), and will render the properly-zoned time in the edit view of that same form.

But when I try to retrieve that same data into a text_field (for the same edit view of the same form), Rails doesn’t seem to adjust for time zone.

/events/edit.html.erb (full file):

<h1>Edit This Event</h1>
<%= form_for(@event) do |f| %>
    <%= render 'fields', :f => f %>
    <div class="actions">
        <%= f.submit "Update Event" %>
    </div>
<% end %>

/events/_fields.html.erb (relevant lines only:)

<div class="field">
    <%= f.label      :time_start, "Start Time" %><br />
    <%= f.text_field  :time_start, :class => "datetimefield" %>
</div>

Example: My zone’s offset is -500. I enter 8:00 as the start_time in the form, 13:00 UTC is written to the database, 8:00 is rendered on the show page (thanks to config.time_zone accounting for the offset), but when I try to edit that object, the form’s text_field for the start_time is loaded with 13:00 (which, if submitted unaltered, becomes 18:00 when it’s stored in the database).

This is problematic, because I’m trying to use jQuery UI’s DatePicker (with a TimePicker add-on), which relies on the text_field (won’t work with a datetime_select).

Is there a way to make Rails apply the config.time_zone offset to text fields?

Running Rails 3.0.5, deploying to Heroku.

Apologies in advance for having asked a very similar question a few weeks ago. The information there still applies, I just have a better understanding of the problem now, so I re-asked.

  • 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-23T12:42:00+00:00Added an answer on May 23, 2026 at 12:42 pm

    As I said in the question, the main problem I had was getting ActiveRecord to apply the existing ‘config.time_zone’ setting to text_fields.

    It turns out that there’s a very simple and future-proof way to make that happen: just explicitly add a :value and pull the exact same data–no extra/new methods to call! In my case, that meant:

    <%= f.text_field  :time_start, :value => f.object.time_start, :class => "datetimefield" %>
    

    This was an intermediary step to another potential solution I was going to try, and I was surprised to find that it worked all on its own (again, working with the ‘config.time_zone’ I’d already set in ‘config/application.rb’).

    I’ve tested it, and it applies the proper DST offset when applicable as well (just as one would expect, since ‘config.time_zone’ is set).

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

Sidebar

Related Questions

When I use <%= f.datetime_select :somedate %> in a form, it generates HTML like:
How can I use .NET DataSet.Select method to search records that match a DateTime?
When I use DateTime.Now I get the date and time from the server point
I want to use the DateTime.TryParse method to get the datetime value of a
I need to use a datetime.strptime on the text which looks like follows. Some
When getting SQL DateTime Resharper suggests to use new DateTime() when value is DBNull.Value
I use this to convert DateTime value into Date and then I add 00:00:00
We use a base entity with properties such as version (datetime needed for NHibernate)
When I use the XML serializer to serialize a DateTime , it is written
Is it possible to use [Range] annotation for dates? something like [Range(typeof(DateTime), DateTime.MinValue.ToString(), DateTime.Today.ToString())]

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.