Skip to content

Instantly share code, notes, and snippets.

@Eitol
Created March 14, 2017 16:22
Show Gist options
  • Save Eitol/7fe6957d2ae58665a28438fc4ae9c29e to your computer and use it in GitHub Desktop.
Save Eitol/7fe6957d2ae58665a28438fc4ae9c29e to your computer and use it in GitHub Desktop.
Return the system timezone in linux
@staticmethod
def get_system_timezone() -> str:
"""
Retorna el timezone del sistema
:return: Ej: America/Caracas
"""
str_timezone = subprocess.getoutput('ls /etc/ -l | grep localtime | awk \'{print $11}\'')
assert str_timezone is not None and len(str_timezone) and \
str_timezone.find('../usr/share/zoneinfo/') != -1, "TIMEZONE_GET_ERROR:"
str_timezone = str_timezone.replace('../usr/share/zoneinfo/', '')
assert len(str_timezone), "INVALID_SYSTEM_TIMEZONE"
return str_timezone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment