Created
March 5, 2014 23:25
-
-
Save raidzero/9378923 to your computer and use it in GitHub Desktop.
Print local time in any timezone by GMT offset (hour & minute)
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
#!/usr/bin/python | |
import time, sys, re | |
OFFSET = sys.argv[1] # get the time offset in hours | |
OPERATION = OFFSET[0] # get the first character in OFFSET | |
if OPERATION != "+" and OPERATION != "-": # we only accept + and - as valid operations | |
print "usage: %s +3.5 (for UTC +3.5 hours)" % sys.argv[0] | |
sys.exit(1) | |
OFFSET = float(re.search("(\d+(\.\d+)?)", OFFSET).group(1)) # pull out offset only, ignoring operator - digit plus an optional decimal then more digits | |
code = 'print time.strftime("%I:%M %p", time.localtime(time.mktime(time.gmtime()) ' + OPERATION + 'OFFSET * 60 * 60))'; exec code # build the code that prints the time based on operator then execute it | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment