# process time

 

# Credit Barton for process_time1()

 

from time import sleep

import time

import datetime

 

def formatSec(seconds):

    micro = int(seconds%1*1000)

    days = float(seconds)/86400

    hours = days%1*24

    minutes = hours%1*60

    seconds = minutes%1*60

    if int(days) > 0:

        outStr = '%d days,' % days

    else:

        outStr = ''

    outStr = ''.join([outStr, '%02d:%02d:%02d' % (hours, minutes, seconds)])

    if micro > 0:

        outStr += ' and %d milliseconds' % micro

    return outStr

   

def process_time1(sec=10):

    startTime = time.time()

   

    for i in range(0,sec):

        sleep(i)

       

    elapsedTime = time.time() - startTime

    t = datetime.time(0,0,int(elapsedTime), int((elapsedTime%1)*1000000))

    print t.isoformat()

 

if __name__ == '__main__':

    t1 = time.time()

    # process_time1(2)

    time.sleep(3.75987)

    t2 = time.time()

    print formatSec(t2-t1)

 

# >>> 00:00:03 and 750 milliseconds

'''

>>> formatSec(17000)

'04:43:20'

>>>

'''