How to get timedelta's minutes and seconds(ex: 2:01)? Is there any formula for this?
I've tried this, but it really didn't work well
minutes = int(diff.seconds/60)
How to get timedelta's minutes and seconds(ex: 2:01)? Is there any formula for this?
I've tried this, but it really didn't work well
minutes = int(diff.seconds/60)
Isayahs answer works great, but if you don't want to use any libraries you could do something similar to this:
minutes = seconds // 60
remainingSeconds = seconds % 60
print(str(minutes) + ":" + str(remainingSeconds))
I may be misunderstanding the question but if you are looking for a timedelta
object where seconds = 121
then:
>>> from datetime import timedelta
>>> timedelta(minutes=2, seconds=1)
datetime.timedelta(seconds=121)