简体   繁体   中英

Convert time object to minutes in Python 2

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM