Tom Lehman
Tom Lehman

Reputation: 89223

Convert times created by Javascript's getTime() method to ruby Time objects

Javascript's getTime() method returns the number of milliseconds since midnight of January 1, 1970.

How do I convert the output of getTime() to a Ruby Time object?

Upvotes: 2

Views: 2466

Answers (1)

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827406

You can use the Time.at method, and divide the JavaScript timestamp value by 1000, since the at method, uses seconds instead of milliseconds, for example:

jsTime = 1252268867928
print Time.at(jsTime/1000)
# Sun Sep 06 20:27:47 +0000 2009

Upvotes: 10

Related Questions