Friday, 26 November 2010

Calculating a time in human readable form (Python)

I was trying to work out the total time of this pcap directory I was working on but didnt want to see a huge number of seconds, so I have written something to change it into a human readable form. It is largely the same as a version I found on the internet but I cant remember where. Apologies.

<><><>

def human_time(secs):
mins, secs = divmod(secs, 60)
hours, mins = divmod(mins, 60)
days, hours = divmod(hours, 24)
weeks, days = divmod(days, 7)
return '%02d weeks %02d days %02d hours %02d mins %02d secs' % (weeks, days,hours, mins, secs)

<><><>

No comments:

Post a Comment