Quantcast
Viewing all articles
Browse latest Browse all 14069

How get local IANA zone name in python 3

In python 3 how to get local zone name (e.g Australia/Sydney)

I tried like this

import datetimelocal_tzname = datetime.datetime.now().astimezone().tzinfoprint(local_tzname)

this outputs like this

AEDT

But I want to output like this which is the local time zone name

Australia/Sydney

I can execute timedatectl in a subprocess and read the output but that is not what I want.The script I am writing need to be executed on several RedHat (7/8/9) Ubuntu servers where I don't have control of available modules. Therefore it must use available modules when python 3 get installed.

Therefore my requirement is

  1. use native python 3 available modules
  2. not to use external commands and read the output (e.g. use subprocess )
  3. Not require any special module to be installed e.g. tzlocal

zoneinfo is a good module to work with IANA format but I couldn't use that to get the system time zone


Viewing all articles
Browse latest Browse all 14069

Trending Articles