0

I've got this piece of code that is doing as I want except I don't want the hours to be in the output. So I only want min:secs. I'm not sure how to get rid of the hours section or if it's possible at all. Any help would be appreciated.

import time
import datetime


def countdown(mins, seconds):
    secs = mins * 60 + seconds
    for i in range(secs + 1):
        with open("Timer2.txt", "w+") as f:
            print(datetime.timedelta(seconds=secs).resolution)
            f.write(str(datetime.timedelta(seconds=secs)))
        secs -= 1
        time.sleep(1)
    with open("Timer2.txt", "w") as f:
        f.write("HT")


if __name__ == '__main__':
    countdown(0, 10)

Thanks, Mitchell

Mitchell
  • 11
  • 1
  • Does this answer your question? [Format timedelta to string](https://stackoverflow.com/questions/538666/format-timedelta-to-string) – Henry Ecker Apr 07 '21 at 13:01

1 Answers1

1

I found a solution. Instead of using timedelta I'm using divmod instead so:

m, s = divmod(secs, 60) 
time_format = "{:02d}:{:02d}".format(m, s) 
print(time_format) 

Inside the with open

Mitchell
  • 11
  • 1