Last active
August 29, 2015 14:19
-
-
Save egrueter-dev/017352e0037121d6f10d to your computer and use it in GitHub Desktop.
Javascript -> Ruby Datetime Conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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