Reputation: 20916
I want to convert a time.time()
object to minutes.
In my program, I did this:
import time
start = time.time()
process starts
end = time.time()
print end - start
Now I have the value 22997.9909999. How do I convert this into minutes?
Upvotes: 0
Views: 531
Reputation: 12239
You've calculated the number of seconds that have elapsed between start
and end
. This is a floating-point value:
seconds = end - start
You can print the number of minutes as a floating-point value:
print seconds / 60
Or the whole number of minutes, discarding the fractional part:
print int(seconds / 60)
Or the whole number of minutes and the whole number of seconds:
print '%d:%2d' % (int(seconds / 60), seconds % 60)
Or the whole number of minutes and the fractional number of seconds:
minutes = int(seconds / 60)
print '%d m %f s' % (minutes, seconds - 60 * minutes)
Upvotes: 1