Skip to content

Instantly share code, notes, and snippets.

@TAJD
Created February 20, 2018 15:50
Show Gist options
  • Save TAJD/054c7f9d703cad473072c21634445193 to your computer and use it in GitHub Desktop.
Save TAJD/054c7f9d703cad473072c21634445193 to your computer and use it in GitHub Desktop.
import time
class Timer:
"""Class to assist with timing functions.
Start timing with
```my_timer = Timer()```
And then get the time with
``` time_get = my_timer.get_time_hhmmss()```
And then restart timer with
```my_timer.restart()```"""
def __init__(self):
self.start = time.time()
def restart(self):
self.start = time.time()
def get_time_hhmmss(self):
end = time.time()
m, s = divmod(end - self.start, 60)
h, m = divmod(m, 60)
time_str = "%02d:%02d:%02d" % (h, m, s)
return time_str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment