[英]Convert time object to minutes in Python 2
I want to convert a time.time()
object to minutes. 我想将time.time()
对象转换为分钟。
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. 现在我的值为22997.9909999。 How do I convert this into minutes? 如何将其转换为分钟?
You've calculated the number of seconds that have elapsed between start
and end
. 您已经计算了从start
到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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.