0

I'd implemented timezone drop down for my project and the values will be stored in database, take for instance i'm in asia/chennai, then the value stored will be GMT +05:30, so when someone from jerusalem checks the database, they'd see my timezone value, rather it should be theirs (GMT +02:00). How to convert the specified value using ruby on rails ?

Antony Mithun
  • 161
  • 1
  • 15
Sap
  • 235
  • 1
  • 15
  • 2
    Probable duplicate of http://stackoverflow.com/questions/5300493/convert-utc-to-local-time-in-rails-3 – Max Williams May 14 '14 at 11:13
  • 1
    take a look here [example apps time-zones](https://github.com/railscasts/106-time-zones-revised/tree/master/youhaiku-after) or this http://stackoverflow.com/a/4269454/1297435 – rails_id May 14 '14 at 11:17

1 Answers1

2

The easiest way is probably to add a timezone to your user model so that your users can set their timezone. You can do this by using the timezone gem https://github.com/panthomakos/timezone

After you have done this, converting a timestamp to their local zone should be as simple as doing: timestamp.in_time_zone(current_user.time_zone) (this is assuming you have a method current_user)

derekyau
  • 2,936
  • 1
  • 15
  • 14