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.
Asked
Active
Viewed 3,562 times
-2

sawa
- 165,429
- 45
- 277
- 381

Taimoor Changaiz
- 10,250
- 4
- 49
- 53
-
1You have a contradition local time <> GMT. What do you want now? – Michael-O Feb 14 '13 at 19:54
-
I need GMT+5 time, but first preference is converting this string to gmt time, Thanks for response – Taimoor Changaiz Feb 14 '13 at 20:08
-
1Sawa what are you doing man instead of answering you are doing childish things. – Taimoor Changaiz Feb 14 '13 at 20:13
-
Sawa is improving your question's grammar, because it wasn't well written. His action was hardly childish, it was to help you. Please read "[Other people can edit my posts?!](http://stackoverflow.com/faq#editing)" for more information. – the Tin Man Feb 15 '13 at 02:41
-
Ok My apologies sawa, thanks for improving grammer :) and thanks to you @the Tin Man – Taimoor Changaiz Feb 15 '13 at 06:57
2 Answers
2
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!

Gui LeFlea
- 795
- 3
- 12
-
thanks @user1863592 but I got your answer when I find mine I also upovter your answer as you responded instantly and accuratly thanks :) – Taimoor Changaiz Feb 14 '13 at 20:53
-1
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/

Taimoor Changaiz
- 10,250
- 4
- 49
- 53