1

In Python 3.x I want to measure the time it takes to execute an operation and print it in the format DD:HH:MM:SS.SSS (pref with the decimals to include milliseconds). Looking around I couldn't find specifically what I am after in this case on the internet.

My code looks like the following at the moment:

import time

t = time.time()
# perform an operation
t = time.time() - t
print('Elapsed time: ' + str(t))

Obviously I am getting everything in seconds and i can't quite get how to use the formatting function on variable t to get exactly what I am after.

rjmd
  • 170
  • 13

1 Answers1

1

Looks like this might help: Python Time Seconds to h:m:s

You can do something similar, but with days included.

Community
  • 1
  • 1
haudarren
  • 425
  • 1
  • 4
  • 12