Search code examples
pythonstringdatedatetimestrftime

Converting time format , string to float


How can I convert a time string '15:04:23' (hours:minuts:seconds) into a float 150423, using python? The following steps had been done yet:

Initially I have the time/date information in the format seconds since 01.01.2000. I converted this using the following function

 t_temp = datetime(2000,1,1)+timedelta(seconds = t)

Then I extracted the time

t_temp.strftime("%H:%M:%S")

... which gives me string


Solution

  • do this

    time = float(t_temp.replace(":",""))
    

    this will remove the colons and typecast the string into float.Works in both python2 and python3

    here are two useful links