开发者

python get time in minutes

开发者 https://www.devze.com 2022-12-29 10:24 出处:网络
import开发者_开发技巧 datetime start = datetime.datetime(2009, 1, 31) end = datetime.datetime(2009, 2, 1)
import开发者_开发技巧 datetime
start = datetime.datetime(2009, 1, 31)
end = datetime.datetime(2009, 2, 1)
print end-start
>>1 day, 0:00:00//output

How to get the output in minutes

Thanks,


import datetime
start = datetime.datetime(2009, 1, 31)
end = datetime.datetime(2009, 2, 1)
diff = end-start
print (diff.days * 1440) + (diff.seconds / 60)
>> 1440.0

(I'm assuming you don't need microsecond resolution here - but if you do, just add in a third term using diff.microseconds with the proper divisor to convert to minutes.)

and after the release of the python 2.7 you can use the method total_seconds

print (diff.total_seconds() / 60)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号