from time import sleep

import time

 

def time_in_seconds(time_str):

    str_list = (time_str.split(":"))

    return float(str_list[0])*3600 + float(str_list[1])*60 + float(str_list[2])

 

def formatSec(seconds):

    milli = 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 milli > 0:

        outStr += ' and %d milliseconds' % milli

    return outStr

 

if __name__ == '__main__':

    t1 = time.time()

    time.sleep(3.75987)

    t2 = time.time()

    print formatSec(t2-t1)

 

    str1 = "23:16:45.75"

    print time_in_seconds(str1)   

 

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

# >>> 83805.75

'''

>>> formatSec(17000)

'04:43:20'

>>>

'''