How to convert HH:MM:SS to seconds in Python

2 Answers

0 votes
h = 2
m = 13
s = 30

seconds = h * 3600 + m * 60 + s

print(seconds)


'''
run:

8010

'''

 



answered Nov 11, 2017 by avibootz
0 votes
def get_seconds(the_time):
    h, m, s = the_time.split(':')
    return int(h) * 3600 + int(m) * 60 + int(s)


print(get_seconds('1:07:31'))


'''
run:

4051

'''

 



answered Nov 12, 2017 by avibootz

Related questions

1 answer 150 views
1 answer 151 views
151 views asked May 1, 2022 by avibootz
1 answer 140 views
1 answer 144 views
1 answer 148 views
1 answer 138 views
1 answer 185 views
...