Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. time = "01:30" # 1 minute and 30 seconds
  2. time2 = time + 10 seconds
  3.  
  4. def format_duration(seconds):
  5. minutes, seconds = divmod(seconds, 60)
  6. hours, minutes = divmod(minutes, 60)
  7. return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)
  8.  
  9. >>> def format_duration(seconds):
  10. ... minutes, seconds = divmod(seconds, 60)
  11. ... hours, minutes = divmod(minutes, 60)
  12. ... return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)
  13. ...
  14. >>> duration = 170
  15. >>> format_duration(duration)
  16. '00:02:50'
  17. >>> duration += 10
  18. >>> format_duration(duration)
  19. '00:03:00'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement