Skip to content

Instantly share code, notes, and snippets.

@saml
Last active December 16, 2015 01:49
Show Gist options
  • Save saml/5358021 to your computer and use it in GitHub Desktop.
Save saml/5358021 to your computer and use it in GitHub Desktop.
# pip install dateutil pytz
import dateutil.parser
import pytz
import traceback
while True:
try:
line = raw_input("> ").strip()
first_space = line.find(' ')
last_space = line.rfind(' ')
src_tz = pytz.timezone(line[0:first_space].strip())
dest_tz = pytz.timezone(line[last_space:].strip())
timestamp = line[first_space:last_space].strip()
t = src_tz.localize(dateutil.parser.parse(timestamp))
print(timestamp)
print('==> %s in %s is %s in %s' % (t.strftime('%b %d, %Y %I:%M %p'), src_tz,
t.astimezone(dest_tz).strftime('%b %d, %Y %I:%M %p'), dest_tz))
except (KeyboardInterrupt, EOFError):
break
except:
traceback.print_exc()
print("Bye!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment