You can't do much in terms of formatted string conversions with a timedelta
. You could just convert to a string and grab the last 5 characters:
>>> r_time = 1000
>>> str(timedelta(seconds=r_time))[-5:]
'16:40'
Other, less hacky ways exist such as the following which does not require mucking about with timedelta
:
>>> time.strftime('%M:%S', time.gmtime(r_time))
'16:40'
>>> time.strftime('%M:%S', time.gmtime(3599))
'59:59'
>>> time.strftime('%M:%S', time.gmtime(3600))
'00:00'
I was tempted by this:
>>> r_time = 1000
>>> f'{r_time//60:02}:{r_time%60:02}'
'16:40'
but then this happens:
>>> r_time = 3600
>>> f'{r_time//60:02}:{r_time%60:02}'
'60:00'