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 228 views
1 answer 238 views
238 views asked May 1, 2022 by avibootz
1 answer 243 views
1 answer 226 views
1 answer 237 views
1 answer 225 views
1 answer 261 views
...