Home Printing time deltas in human readable format for python
Post
Cancel

Printing time deltas in human readable format for python

From time to time I want to be able to log time deltas in a way that is easy for me to read. I normally write my own code to do this. But the other day I figured there must have been an easier way. Turns out there is.

1
2
3
import datetime
print(datetime.timedelta(seconds=1234))
0:20:34

The datetime module has a timedelta command in it that will do exactly what I wanted. So that saved me some time yesterday.

This post is licensed under CC BY 4.0 by the author.