Skip to content

Instantly share code, notes, and snippets.

@damoxc
Created July 28, 2014 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damoxc/096363ec0a819b35317c to your computer and use it in GitHub Desktop.
Save damoxc/096363ec0a819b35317c to your computer and use it in GitHub Desktop.
A simple clock in Py3
#!/usr/bin/python3
import sys
import time
import datetime
BS_CHAR = '\u0008'
DATE_FMT = '%Y-%m-%d %H:%M:%S'
def clock():
while True:
now = datetime.datetime.now()
sys.stdout.write(BS_CHAR * 40)
sys.stdout.write(now.strftime(DATE_FMT))
sys.stdout.flush()
time.sleep(1) # sleep for 1 second
def main():
try:
clock()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment