Convert seconds in minutes, hours, days, years ...
Dan Bishop
danb_83 at yahoo.com
Fri Jan 17 11:11:32 EST 2003
Loko at caramail.com (Loko) wrote in message news:<399d6c30.0301170024.8142cbf at posting.google.com>...
> This is not exactly what I wanted,I want integers. Thus I wrote :
>
> def Fract_Sec(s):
> temp = float()
> temp = float(s) / (60*60*24)
> d = int(temp)
> temp = (temp - d) * 24
> h = int(temp)
> temp = (temp - h) * 60
> m = int(temp)
> temp = (temp - m) * 60
> sec = temp
> return d,h,m,sec
> #endef Fract_Sec
This could be simplified my using the divmod function.
def fractSec(s):
years, s = divmod(s, 31556952)
min, s = divmod(s, 60)
h, min = divmod(min, 60)
d, h = divmod(h, 24)
return years, d, h, min, s
More information about the Python-list
mailing list