Created
May 25, 2013 19:26
-
-
Save benshimmin/5650448 to your computer and use it in GitHub Desktop.
Working with JavaScript epoch times in Ruby
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
# Ruby's epoch times are three digits shorter than JavaScript's, | |
# which need only be slightly annoying: | |
class Time | |
def self.at_from_js(date) | |
self.at date.to_i / 1000 | |
end | |
end | |
Time.at(1369503558784) # 45367-11-03 15:13:04 +0000 | |
Time.at_from_js(1369503558784) # 2013-05-25 18:39:18 +0100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment