-2

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)
Delta888
  • 84
  • 6

2 Answers2

3

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))
Simplicitus
  • 161
  • 1
  • 9
0

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)

Isayah
  • 39
  • 1
  • 8