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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:45:36+00:00 2026-05-24T22:45:36+00:00

I have set config.time_zone = ‘Berlin’ config.active_record.default_timezone = :local in application.rb and restartet WEBrick

  • 0

I have set

config.time_zone = 'Berlin'
config.active_record.default_timezone = :local

in “application.rb” and restartet WEBrick Webserver an “remigrated” (rake db:drop; rake db:migrate) my database.

If I check Entries in my Database, everything is fine and the “created_at” is correctly saved in my Localtimezone:

sqlite> select created_at from docversions;
2011-08-22 23:27:51.138723
sqlite>

But in this case, this “Local Timezone” doesnt work:

(creat.html.erb)

<%= form_for :token, :url => {:action => "save_token"}, :docversion_id => params[:id] do |f| %>
<%= f.datetime_select :validuntil, :order => [:day, :month, :year, :hour, :minute], :default => 3.days.from_now,  %>
<%= f.submit %>

(tokenadmin_controller.rb)

class TokenadminController < ApplicationController
  def save_token
    @token = Token.new
    civildate = DateTime.civil(params[:token]["validuntil(1i)"].to_i,
                               params[:token]["validuntil(2i)"].to_i,
                               params[:token]["validuntil(3i)"].to_i,
                               params[:token]["validuntil(4i)"].to_i,
                               params[:token]["validuntil(5i)"].to_i)
    @token.validuntil = civildate
    if @token.save
      flash[:notice] = "Token created."
      redirect_to :controller => :tokenadmin, :action => :admin
    else
      flash[:error] = "Token could not be saved!"
      redirect_to :controller => "index"
    end 
  end 
end

It seems that it would be saved as UTC:

sqlite> select validuntil, created_at from tokens;
2011-08-22 01:44:00.000000|2011-08-22 23:44:20.640434
sqlite>

As you can see, created_at is correctly saved as Localtime, but validuntil is saved +2h (but i have selected the same time as create_at ;-)). I think its +2h because were in a timezone wich is UTC+1 and in DST UTC+2. And were in DST at the moment.

Is that a bug, or did I do something wrong?

Thanks for your help.

UPDATE AFTER POST FROM “BaronVonBraun”:

Thanks! Its working now.
Databasefield is still “timestamp”:

t.timestamp :validuntil

Controller code, wich is use to create a Time-field:

Before:

civildate = DateTime.civil(params[:token]["validuntil(1i)"].to_i,
                           params[:token]["validuntil(2i)"].to_i,
                           params[:token]["validuntil(3i)"].to_i,
                           params[:token]["validuntil(4i)"].to_i,
                           params[:token]["validuntil(5i)"].to_i)

After:

civildate = Time.parse("#{params[:token]["validuntil(1i)"].to_s}-#{params[:token]["validuntil(2i)"].to_s}-#{params[:token]["validuntil(3i)"].to_s} #{params[:token]["validuntil(4i)"].to_s}:#{params[:token]["validuntil(5i)"].to_s}")
  • 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-24T22:45:38+00:00Added an answer on May 24, 2026 at 10:45 pm

    DateTime objects are in GMT/UTC (+0000 offset) by default.

    If you want to store your local timezone along with your date object, I’d suggest using Time instead of DateTime, which should use the timezone you’ve set in your Rails config.

    If you need to continue using DateTime, here is an answer to another question: How do I alter the timezone of a DateTime in Ruby?. However, in that solution, it sets the timezone to a hard offset, meaning it wouldn’t handle going in and out of DST.

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

Sidebar

Related Questions

I have config.time_zone in environment.rb set to UTC, and my mySQL server returns the
In my application I have: config.time_zone = 'Warsaw' A strange issue I have, is
I have set an array in my config file that I use global in
I have set UserIsOnlineTimeWindow =2 in web.config then my logout() function has been modified
We have a set of tables and views that merely store some config data
I have a problem with using use_page_numbers config set to true in my pagination
I have authentication mode set to forms in my asp.net web.config but am still
in my config.php where i have all constants i set the PATH to a
I have a windows service that has it's name set by an app.config. I
How can i set default home page in asp web.config file. i have already

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.