From: Utsav Gupta on 22 Mar 2010 14:06 I receive the dates from Twitter in the following format "Mon Mar 22 04:42:17 +0000 2010" Now how can I create a time object from this string... ie Obj.year=2010, Obj.month=3... etc etc Regards Utsav Gupta -- Posted via http://www.ruby-forum.com/.
From: Chuck Remes on 22 Mar 2010 14:19 On Mar 22, 2010, at 1:06 PM, Utsav Gupta wrote: > I receive the dates from Twitter in the following format "Mon Mar 22 > 04:42:17 +0000 2010" > > Now how can I create a time object from this string... ie Obj.year=2010, > Obj.month=3... etc etc Quite simple. cremes$ irb ruby-1.9.1-p378 > require 'time' => true ruby-1.9.1-p378 > s = "Mon Mar 22 04:42:17 +0000 2010" => "Mon Mar 22 04:42:17 +0000 2010" ruby-1.9.1-p378 > t = Time.parse s => 2010-03-21 23:42:17 -0500 ruby-1.9.1-p378 > t.month => 3 ruby-1.9.1-p378 > t.year => 2010 Note that Time.parse creates your time object with the local timezone. You can still access zulu time by using the #utc method on that object. cr
|
Pages: 1 Prev: Any idea of SciTE-ru supporting ruby? Next: Sorting keys of hash based on value |