lines python timechart
| # usage: | |
| # $ python3 ltc.py "America/Chicago" "8/27/2020 15:00" | |
| # 01PM MST | |
| # 01PM PDT | |
| # ... | |
| # 04:00 AWST | |
| # 04:45 +0845 | |
| # ... | |
| import pytz, datetime, argparse | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('here') | |
| ap.add_argument('heretime') | |
| ar = ap.parse_args() | |
| here = ar.here #'America/Chicago' | |
| heretime = ar.heretime #'8/27/2020 15:00' | |
| us_fm = '%I%p %Z' | |
| fm = '%H:%M %Z' | |
| utc = pytz.timezone(here).localize(datetime.datetime.strptime(heretime, '%m/%d/%Y %H:%M')).astimezone(pytz.utc) | |
| tc = [] | |
| # the US gets it's own loop for our silly 12-hour clocks | |
| for c in ['us']: | |
| for tz in ['America/Los_Angeles', 'America/Phoenix', 'America/Chicago', 'America/New_York']: | |
| tc.append(utc.astimezone(pytz.timezone(tz)).strftime(us_fm)) | |
| tc = list(dict.fromkeys(tc)) | |
| tc.sort() | |
| for tz in tc: | |
| print(tz) | |
| tc = [] | |
| for c in ['gb', 'no', 'de', 'se', 'it', 'jp', 'fi', 'au']: | |
| for tz in pytz.country_timezones[c]: | |
| tc.append(utc.astimezone(pytz.timezone(tz)).strftime(fm)) | |
| tc = list(dict.fromkeys(tc)) | |
| tc.sort() | |
| for tz in tc: | |
| print(tz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment