% systemsetup -gettimezone
You need administrator access to run this tool... exiting!
def _get_localzone():
pipe = subprocess.Popen(
"systemsetup -gettimezone",
shell=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE
)
tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()
if not tzname or tzname not in pytz.all_timezones_set:
# link will be something like /usr/share/zoneinfo/America/Los_Angeles.
link = os.readlink("/etc/localtime")
tzname = link[link.rfind("zoneinfo/") + 9:]
return pytz.timezone(tzname)
This is on macOS Sierra 10.12.3 (16D32)
% systemsetup -gettimezone You need administrator access to run this tool... exiting!