Skip to content

Instantly share code, notes, and snippets.

@karthikbgl
Created October 23, 2014 15:36
Embed
What would you like to do?
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