Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,961 questions

51,903 answers

573 users

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 121 views
1 answer 127 views
127 views asked May 1, 2022 by avibootz
1 answer 118 views
1 answer 114 views
1 answer 118 views
1 answer 104 views
1 answer 157 views
...