Strange output after date conversion in Ruby on Rails
I am getting data from an API. The date attached to each object comes in this format:
Timestamp is the date and time of an event in UTC time. This is expressed as a specific number of milliseconds since the standard base "epoch" of: January 1, 1970, 00:00:00 GMT
I am trying to convert this into a different date format in Ruby.
CODE
objects.each do |obj|
p "object"
p obj.created
p Time.at(obj.created)
end
OUTPUT
"object"
1308886130000
43446-12-14 10:33:20 +1000
"object"
1308886104000
43446-12-开发者_如何学JAVA14 03:20:00 +1000
"object"
1308801345000
43444-04-07 03:10:00 +1000
The years are obviously incorrect. What am I doing wrong?
I am using Ruby 1.9.2 and Rails 3.0.1
The Time.at
function expects time since the epoch in seconds. You're giving it milliseconds, so the calculation is way off.
Divide that timestamp by 1000.
精彩评论