Skcript Technologies Private Limited

← All Articles

Offsetting Ruby Time

— Written by

Offsetting Ruby Time

Managing local time is such a huge challenge when making web apps. Here's an easy way.

Managing local time is such a huge challenge when making webapps. There’s always going to be users from all over the world clocking in on different timezones. Basecamp’s local_time solves this problem in a elegant way – it doesn’t care how you store timezone, it interprets the users local time and prints it out on the view accordingly.

But, all hell breaks loose when you try to recreate this on the server side. Here there’s no information on what user is from what timezone.

And even if you persist the users timezone information, surprisingly Rails doesn’t come with an out of the box solution to offseting time(s).

Here’s a super simple way to convert a UTC time to a zone of your choice, by just inputting the offset.

  t =
  => Fri, 22 Jul 2016 07:56:38 UTC +00:00
  => Fri, 22 Jul 2016 13:26:38 UTC +00:00

{% gist 4d20c8989172351268173c4f16421208 %}

Up next

Five things to consider when choosing enterprise productivity applications
Skcript /svr/offsetting-ruby-time/ /svrmedia/heroes/offsetting-ruby.jpg
Skcript Technologies Private Limited

Book a free consultation

Book a time with our consultants to discuss your project and get a free quote. No strings attached.