Python Time conversion h:m:s to seconds

datetime, formatting, python

Solution

def hms_to_seconds(t):
    h, m, s = [int(i) for i in t.split(':')]
    return 3600*h + 60*m + s

Problem

I am aware that with the timedelta function you can convert seconds to h:m:s using something like: ``` >> import datetime >> str(datetime.timedelta(seconds=666)) '0:11:06' ``` But I need to convert h:m:s to seconds, or minutes. Do you know a function that can do this?

Original source

Related problems