I need to convert the following strings into either datetimes or strings in a different format. My input looks like these examples:
196h 26m 13s
95h 19m
45m 28s
My desired string output would be (But my final goal is to convert these strings into datetime
objects):
196:26:13
95:19:00
00:45:28
In Excel, it would be [h]:mm:ss
.
Note: As you can see, hours can be higher than 24.
I have tried to parse this string with the time.strptime()
method, but it doesn't work with hours higher than 24. I have a solution with regular expressions, but I want to know if there is a more straightforward way to do this. What is the best way to solve this?
datetime
,date
, andtime
are entirely the wrong types to use; the correct type istimedelta
, which does not have a built-in string-parsing method.