Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
Last active August 29, 2015 14:19
Show Gist options
  • Save egrueter-dev/017352e0037121d6f10d to your computer and use it in GitHub Desktop.
Save egrueter-dev/017352e0037121d6f10d to your computer and use it in GitHub Desktop.
Javascript -> Ruby Datetime Conversion
var d = new Date(1394648309130.185)
d // Wed Mar 12 2014 11:18:29 GMT-0700 (Pacific Daylight Time)
d.getTime()
// 1394648309130 // Fractions of a millisecond are dropped
In ruby:
t = Time.now
# => 2014-03-12 11:18:29 -0700
t.to_f * 1000 # convert to milliseconds since 1970-01-01 00:00:00 UTC.
# => 1394648309130.185
This value can be directly given to the JavaScript Date constructor:
Deciper Javascript timestamp
Time.at( 1394648309130 / 1000.0 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment