# Rails 2.1 UTC & Local Time

**URL:** <https://www.ruby-forum.com/t/rails-2-1-utc-local-time/145434>\
**Category:** Rails\
**Created:** [August 9, 2008, 8:33am UTC](https://www.ruby-forum.com/t/rails-2-1-utc-local-time/145434 "2008-08-09T08:33:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 9, 2008, 8:33am UTC](https://www.ruby-forum.com/t/rails-2-1-utc-local-time/145434/1 "2008-08-09T08:33:29Z")

</div>

I wrote the follwoing code to force the time before saving a record  
(using UTC in my config environment)

```
  e = self.ending_at
  self.starting_at = Time.utc(s.to_date.year, s.to_date.month,

```

s.to\_date.day, 0, 0, 1)

self.starting\_at  
=\> Fri, 01 Feb 2008 00:00:01 UTC +00:00

BUT now, I would like to use time zones in my app (setting  
config.time\_zone = “Madrid”)  
the user gives a date in the form (Fri, 01 Feb 2008)  
the time is forced to be 00:00:01 as above  
the date is saved as being Fri, 01 Feb 2008 00:00:01 in Madrid (UTC +  
01:00)

any trick ?

erwin

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [August 11, 2008, 12:00am UTC](https://www.ruby-forum.com/t/rails-2-1-utc-local-time/145434/2 "2008-08-11T00:00:31Z")

</div>

you want to set the database to use utc in environment.rb :  
config.time\_zone = ‘UTC’

And then store users timezone in your DB and then set config.timezone in  
a  
before\_filter in your app.

That will allow the users to deal with their local timezone , but store  
everything in UTC.

> **[Mad Mimi Email Marketing](https://madmimi.com)**
>
> Mad Mimi makes it simple to send HTML email newsletters, grow your subscribers and manage your email list. Sign up today!

Adam
