Skip to content

Instantly share code, notes, and snippets.

@karthikbgl
Created October 23, 2014 15:36
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 karthikbgl/33ed3afd98e842b9c4d1 to your computer and use it in GitHub Desktop.
Save karthikbgl/33ed3afd98e842b9c4d1 to your computer and use it in GitHub Desktop.
Time elapsed in seconds
def secondsToStr(t):
'''
This snippet converts the time elapsed in
seconds to HH:MM:SS.mmm
Example:
>>> secondsToStr(123456)
'34:17:36.000'
'''
return "%d:%02d:%02d.%03d" % \
reduce(lambda x, y: divmod(x[0], y) + x[1:],
[(t*1000,), 1000, 60, 60])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment