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 227 views
1 answer 234 views
234 views asked May 1, 2022 by avibootz
1 answer 241 views
1 answer 222 views
1 answer 236 views
1 answer 223 views
1 answer 260 views
...