Question

I have an ISO-8601 datetime stamp, and need to convert it into local time in GMT. What is the way to do it in Ruby on Rails? I have '1325233011', and need to convert it into local time in GMT standards.

Was it helpful?

Solution

I think what you're asking for is a locale time in GMT+5.

Given an ISO timestamp, 1325233011

When I convert this to a locale-based date/time

Time.at(1325233011) => '2011-12-30 03:16:51 -0500'

Take a look at the ruby-docs, http://www.ruby-doc.org/core-1.9.3/Time.html for more information. Ruby has robust Time and Date classes with many helper utilities. My machine is configured for GMT-5 so it returns the local time. It's easy to change the way timezone settings are interpreted in your program, but that's for another day. Hope this helps!

OTHER TIPS

From Collegue's help got it

Time.at(1325233011).to_datetime

For Iso-8601:

Time.at(1325233011).to_datetime.iso8601

For verification of time correct conversion and comparision use this link http://coderstoolbox.net/unixtimestamp/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top