2012-12-15 220 views
1
{"creator"=>{"siteStandardProfileRequest"=>{"url"=>"http://www.linkedin.com/profile?viewProfile=&key=966636&authToken=TVqk&authType=name&trk=api*a188142*s196271*"}, "lastName"=>"Emge", "id"=>"EZDn5fpc6X", "pictureUrl"=>"http://m3.licdn.com/mpr/mprx/0_gxkFOrh6iNKSaMhhxOX4OPnLizvm2VTh0ZKZOPFJpPTY1Yn8AMNIK1PcD4zl7j82yyQJAqJM7R4U", "firstName"=>"Ryan O."}, "creationTimestamp"=>1355124057000, "text"=>"Being that it positions itself as a the backbone of the internet, it appears that there will be many long term opportunities in this space.", "id"=>"g-66325-S-194331620-108220061"} 

creationTimestamp具有這種格式1355124057000。我想將其更改爲Sat Dec 15 04:13:14 +0000 2012。我在軌道上使用紅寶石,紅寶石1.8.7和軌道3.0.4
我該如何改變這一點?時間解析紅寶石

+0

請確保該字段的數據類型是'datetime'或其他。 – VenkatK

回答

1

我猜你正在尋找Time.at功能

t = Time.at(1355124057) # for seconds since epoch 
t = Time.at(1355124057000/1000) # for milliseconds since epoch 

這是在幾秒鐘內since epoch(1970年1月1日00:00:00 GMT),一旦你的時間對象的時間

t適用strftime的時間轉換爲whichver方式你喜歡

所以你的情況的字符串,這將是

t.strftime("%a %b %d %H:%m:%S %z %Y") 
+0

噸= Time.at(1355124057000) 的RangeError:BIGNUM太大而轉換成'長 ' \t從(IRB):6:'在' \t從(IRB):6我有這種類型的錯誤 – user1488812

+0

我的認爲你有太多的零到最後。 它應該是1355124057而不是更多。檢查一下 – Garfield

+0

如果最後確實有000,那麼它的歷史可能是幾百毫秒? 所以你總是可以做一個1355124057000/1000轉換成秒數 – Garfield