Last active
December 16, 2015 01:49
-
-
Save saml/5358021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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