Skip to content

Instantly share code, notes, and snippets.

@benshimmin
Created May 25, 2013 19:26
Show Gist options
  • Save benshimmin/5650448 to your computer and use it in GitHub Desktop.
Save benshimmin/5650448 to your computer and use it in GitHub Desktop.
Working with JavaScript epoch times in Ruby
# 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