I'm a newbie to python. I was trying to display the time duration. What I did was:
startTime = datetime.datetime.now().replace(microsecond=0)
... <some more codes> ...
endTime = datetime.datetime.now().replace(microsecond=0)
durationTime = endTime - startTime
print("The duration is " + str(durationTime))
The output is => The duration is 0:01:28 Can I know how to remove hour from the result? I want to display => The duration is 01:28
Thanks in advance!
You can do this by converting
durationTime
which is adatetime.timedelta
object to adatetime.time
object and then usingstrftime
.Another way would be to manipulate the string: