Skip to content

Instantly share code, notes, and snippets.

@embayer
Last active August 29, 2015 14:07
Show Gist options
  • Save embayer/9baba71576e09c839265 to your computer and use it in GitHub Desktop.
Save embayer/9baba71576e09c839265 to your computer and use it in GitHub Desktop.
print a duration in human readable format
import datetime
import time
class Duration:
def __init__(self, start_time=None, end_time=None):
self.start_time = start_time
self.end_time = end_time
def start(self):
self.start_time = time.time()
def stop(self):
self.end_time = time.time()
def print_duration(self):
duration = self.end_time - self.start_time
print str(datetime.timedelta(seconds=int(duration)))
d = Duration()
d.start()
time.sleep(3)
d.stop()
d.print_duration()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment