Forum: Ruby on Rails Newbee question - problem with timezones

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mikkel WF (Guest)
on 2006-12-29 21:29
(Received via mailing list)
Hello

I've developed a rails application locally (Denmark), and have now
uploaded it to my server, witch is located in the US.

What didn't come to my attention in the development face was the
difference in time zones.

I'v tried setting the "default_timezone"-tag i environment.rb, but the
time it still rendered wrong.

SO HOW THE HELL CAN I CHANGE APPLICATIONS TIME ZONE..??

Help anyone, please!!
Andrew S. (Guest)
on 2006-12-30 12:37
(Received via mailing list)
> I've developed a rails application locally (Denmark), and have now
> uploaded it to my server, witch is located in the US.
>
> What didn't come to my attention in the development face was the
> difference in time zones.
>
> I'v tried setting the "default_timezone"-tag i environment.rb, but the
> time it still rendered wrong.

The least confusing approach, in my opinion, is to use UTC everywhere.

I assume you mean you have set the default timezone in environment.rb
to :utc.

Consequently, when storing times in the database, you should use
Time.now.utc instead of Time.now.

When displaying times in your views, use a helper to convert from UTC
to the user's local time zone.

I sympathise with your frustration.  Time zones can be fiddly but,
once everything is configured correctly, you can forget about them
(until you deploy your next app on new servers when you won't be able
to remember quite what you did the previous time to get it all
working :).

If you've set Rails up to use UTC and you're still having trouble,
it's worth checking that your app server and database server have
their system clocks and timezones set correctly....  That's caught me
out in the past and it was infuriating.

Regards,
Andy S.
This topic is locked and can not be replied to.