0

I'm using the following to display the time at which a musing entry was created:

<%= l musing.created_at, :format => "%d/%m/%y at %I:%M %p" %>

And the time is delayed by 5 hours, for example if I generate a musing at "2012-10-30 19:21:35 -0700", this is the time displayed:

31/10/12 at 02:21 am  by me@benigeri.com
Chris Travers
  • 25,424
  • 6
  • 65
  • 182
Paul Benigeri
  • 157
  • 2
  • 8
  • 5
    What timezone (UTC offset) is your server in? What about your database? – Matt Ball Oct 31 '12 at 02:25
  • Is the field a `timestamp` or a `timestamptz` in the database table? – Craig Ringer Oct 31 '12 at 02:30
  • @MattBall I don't know what timezone offset my server is in, I'm located in Palo Alto, CA, and this happens both on local host and heroku. – Paul Benigeri Oct 31 '12 at 02:46
  • @CraigRinger I'm not sure, I just added 't.timestamps' in the migration file, so I am using that. – Paul Benigeri Oct 31 '12 at 02:47
  • @Craig: Rails implies `timestamp` in the database and everything normalized to UTC in the database as well. – mu is too short Oct 31 '12 at 02:48
  • Add `%z` or `%Z` to your `:format` and you'll see what timezone Rails is using. – mu is too short Oct 31 '12 at 02:51
  • @muistooshort Thanks. As you may've guessed I don't generally work with Rails. What an odd way of doing it ... they could use `timestamptz` and either set `timezone` to `UTC` and it'd (IMO) make much more sense than storing timestamps that're *assumed* to be UTC. – Craig Ringer Oct 31 '12 at 02:52
  • @Craig: Come to Whistler for Australia Day and we'll grumble and complain about ActiveRecord's strange and bizarre ideas about databases over a pint or eleven. Too much opinion and not enough good sense. – mu is too short Oct 31 '12 at 03:00
  • This [related answer](http://stackoverflow.com/a/9576170/939860) may help to understand how it works. – Erwin Brandstetter Nov 01 '12 at 00:18

0 Answers0