Converting milliseconds to human time

Max Erickson maxerickson at gmail.com
Fri Jan 6 21:32:42 CET 2006


the hard way(in that you have to do it yourself):

def prntime(ms):
	s=ms/1000
	m,s=divmod(s,60)
	h,m=divmod(m,60)
	d,h=divmod(h,24)
	return d,h,m,s

>>> print '%d days %d hours %d minutes %d seconds' % prntime(1000000)
0 days 0 hours 16 minutes 40 seconds
>>> print '%d days %d hours %d minutes %d seconds' % prntime(10000000)
0 days 2 hours 46 minutes 40 seconds
>>> print '%d days %d hours %d minutes %d seconds' % prntime(100000000)
1 days 3 hours 46 minutes 40 seconds
>>> print '%d days %d hours %d minutes %d seconds' % prntime(1000000000)
11 days 13 hours 46 minutes 40 seconds
>>> print '%d days %d hours %d minutes %d seconds' % prntime(418235000)
4 days 20 hours 10 minutes 35 seconds
>>> 

max




More information about the Python-list mailing list