# Sqlite crazy timezone

**URL:** <https://www.ruby-forum.com/t/sqlite-crazy-timezone/170164>\
**Category:** Rails\
**Created:** [June 13, 2009, 2:40am UTC](https://www.ruby-forum.com/t/sqlite-crazy-timezone/170164 "2009-06-13T02:40:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@steux](https://www.ruby-forum.com/u/steux)\
**Post date:** [June 13, 2009, 2:40am UTC](https://www.ruby-forum.com/t/sqlite-crazy-timezone/170164/1 "2009-06-13T02:40:25Z")

</div>

Hi everyone,  
I am using sqlite3-ruby for my rails application.  
My computer timezone is -3:00 GMT. But when a entry is saved in sqlite3  
database it records 0:00 GMT timestamps.  
If it is 14:00 now, created\_at timestamp will be 17:00.

How can I fix that?

---

<div class="post-metadata">

**Author:** ![steux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@steux](https://www.ruby-forum.com/u/steux)\
**Post date:** [June 13, 2009, 5:15am UTC](https://www.ruby-forum.com/t/sqlite-crazy-timezone/170164/2 "2009-06-13T05:15:23Z")

</div>

You don’t “fix” that, Rails store the dates using the UTC timezone so  
it can show it in ANY other timezone in the views, active record will  
automatically change all dates to your current timezone when showing  
them in the view.

- 

Maurício Linhares  
[http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) | [http://twitter.com/mauriciojr](http://twitter.com/mauriciojr)

On Fri, Jun 12, 2009 at 9:40 PM, Bruno

---

<div class="post-metadata">

**Author:** ![steux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@steux](https://www.ruby-forum.com/u/steux)\
**Post date:** [June 13, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/sqlite-crazy-timezone/170164/3 "2009-06-13T17:51:21Z")

</div>

So as Maricio is pointing out, Rails stores the time in UTC format by  
default, but you can set it to display the time in the preferred zone  
format. For example, I am in the eastern time zone and would like my  
application to display time in EST. To do that, use the following  
setting in  
RAILS\_ROOT/config/environment.rb file:

# Make Time.zone default to the specified zone, and make Active

Record store time values

# in the database in UTC, and return them converted to the specified

local zone.

# Run “rake -D time” for a list of tasks for finding time zone

names.  
config.time\_zone = “Eastern Time (US & Canada)”

To see other time zones available and how to represent them in time  
zone string as shown above, please lookup the Rails documenation.

Hope this helps.

Bharat
