Centos – Get current timezone on CentOS 7

centossedtimezone

On previous version of CentOS, I used the following command to get the current timezone in my bash script:

timezone=$(sed 's/ZONE=//g' /etc/sysconfig/clock)

Output is
"America/New_York"

How can I achieve an exact output on CentOS 7?

Best Answer

CentOS 7 specific:

timedatectl | gawk -F': ' ' $1 ~ /Timezone/ {print $2}'

And displaying just the timezone:

timedatectl | gawk -F'[: ]+' ' $2 ~ /Timezone/ {print $3}'

more generic:

date +%Z
Related Question