Last active
October 9, 2015 20:39
-
-
Save vinovator/f7216904184f7ab36c57 to your computer and use it in GitHub Desktop.
Simple query to fetch all common time zones and their current time
This file contains hidden or 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
# Python 2.7.6 | |
# timeZoneExplorer.py | |
from pytz import timezone, common_timezones # import all_timezones for more exhaustive list | |
from datetime import datetime | |
import os | |
# Log file will be created in the same folder as the python script | |
my_path = "." | |
log_path = os.path.join(my_path + "/" + "loc_log.txt") | |
fmt = "%Y-%m-%d %H-%M-%S %Z%z" | |
fixed_length = 32 | |
with open(log_path, "w") as my_log: | |
for zone in common_timezones: | |
local_time = datetime.now(timezone(zone)).strftime(fmt) | |
space = fixed_length - len(zone) | |
#my_log.write("{0} : {1}".format(zone, local_time)) | |
my_log.write("{0}{1}:{2}".format(zone, " "*space, local_time)) | |
#my_log.write(zone + " "* space + ":" + local_time) | |
my_log.write("\n") | |
print ("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment