0

I'm trying to change default timezone in Rails 3.2.8 app to GMT+04:00, but I don't know how to do it. The following solutions do not work for me:

config.time_zone = 'Moscow'
config.time_zone = "(GMT+04:00) Moscow"
config.active_record.default_timezone = 'Moscow'
config.active_record.default_timezone = :local

Also I've tried in rails console the following:

 ActiveSupport::TimeZone.all.map(&:name)

which returned a list of values, including "Moscow". Time.zone returned (GMT+00:00) UTC which is not correct, it should be (GMT+04:00) UTC. Then I changed Time.zone = "Moscow" and Time.now returned the correct value (... +0400).

So to fix it I simply used Time.now + 4.hour, but I also need datetime_select to display my local time. Time.now + 4.hour is not a correct solution.

How one can set default time zone to their local value?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Ilya Chernov
  • 411
  • 7
  • 18
  • 2
    Have you checked out a recently revise RailsCast on this topic? http://railscasts.com/episodes/106-time-zones-revised?view=asciicast – Tom Harrison Dec 06 '12 at 21:25

1 Answers1

0

All of a sudden I've localized the problem. I run Win7 and my WEBrick server is showing the correct time, but the project itself shows a wrong one. In the same time, my production server is working correctly, so, obviously, the problem is with the OS. UPD: The problem is fixed. I should have restarted the WEBrick server after changing the application.rb file.

Ilya Chernov
  • 411
  • 7
  • 18
  • If you have updates to questions, please use the edit link, and change the original question, rather than adding an answer. – Tom Harrison Dec 06 '12 at 21:23
  • 1
    Tom, I've found the solution even before I've posted the question, but after I was ready to. So I decided to use the "Post your question and answer" button. Btw thanks for the link above.. – Ilya Chernov Dec 07 '12 at 17:30