1

I have a string '3hours26minutes33seconds' and I need to convert this into HH:MM:SS format. I tried using dateutil.parser.parse to no avail.

Ravi Teja
  • 19
  • 2

1 Answers1

3

You can use datetime and its strptime function to convert it to a datetime object:

import datetime

string = "3hours26minutes33seconds"
date = datetime.datetime.strptime(string, "%Hhours%Mminutes%Sseconds")

Then you format that datetime into the desired string format with strftime:

date.strftime("%H:%M:%S")
Falx
  • 201
  • 1
  • 5