Skip to content

Instantly share code, notes, and snippets.

@passalini
Created October 24, 2014 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passalini/3a84478ee5bdbfc1b112 to your computer and use it in GitHub Desktop.
Save passalini/3a84478ee5bdbfc1b112 to your computer and use it in GitHub Desktop.
Milliseconds to timestamp
# based in http://stackoverflow.com/a/10874157
def to_timestamp(x)
y = 60*60*1000
h = x/y
m = (x-(h*y))/(y/60)
s = (x-(h*y)-(m*(y/60)))/1000
mi = x-(h*y)-(m*(y/60))-(s*1000)
string = "#{h.to_s.rjust(2, '0')}:#{m.to_s.rjust(2, '0')}:#{s.to_s.rjust(2, '0')},#{mi.to_s.rjust(3, '0')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment