Skip to content

Instantly share code, notes, and snippets.

@lananhbk168
Forked from morion4000/countdown.py
Last active August 29, 2015 14:24
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 lananhbk168/473262300087c4e88e0e to your computer and use it in GitHub Desktop.
Save lananhbk168/473262300087c4e88e0e to your computer and use it in GitHub Desktop.
from datetime import datetime, time
def dateDiffInSeconds(date1, date2):
timedelta = date2 - date1
return timedelta.days * 24 * 3600 + timedelta.seconds
def daysHoursMinutesSecondsFromSeconds(seconds):
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
return (days, hours, minutes, seconds)
leaving_date = datetime.strptime('2012-01-01 01:00:00', '%Y-%m-%d %H:%M:%S')
now = datetime.now()
print "%d days, %d hours, %d minutes, %d seconds" % daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, leaving_date))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment