The time duration is being described using four sets of double digits numbers separated with columns such as 00:02:01:16.
I know that this represents a time interval or a time duration.
I would like to translate it to a single number that represents a time duration in a more common form such as "120 seconds" or "12 minutes". What approach should be taken here?
Asked
Active
Viewed 121 times
0
alphanumeric
- 15,954
- 55
- 201
- 355
-
Have you tried the things listed in this post? http://stackoverflow.com/questions/10663720/converting-a-time-string-to-seconds-in-python – jhack Oct 13 '16 at 22:29
2 Answers
1
", ".join((a+b for a,b in zip(time_s.split(":")," hour(s), min(s), second(s), ms".split(","))))
Joran Beasley
- 103,130
- 11
- 146
- 174
0
You need to use timedelta.
from datetime import timedelta
Assume your time 00:02:01:16 is stored in a, which comes from end_time - start_time
This will be automatically be a timedelta object. Then you can use a.total_seconds() to get the seconds information.
Check Timedelta Documentation for more usage and examples
Bing Gan
- 385
- 3
- 5
- 11