Check The Timezone in Linux

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

In this small guide, I will explain how to check timezone in Linux using 4 Easy Methods. System time is usually defined by timezone. Please aware that entire globe divided into multiple timezones which determines its local time.

There are a number of time management utilities available on Linux such as date and timedatectl commands to get the current timezone of system and synchronize with a remote NTP server to enable an automatic system time handling.

Hence I will try to explain different methods through examples using which one can check the timezone in their Linux Based Systems.

Starting with using the traditional date command to find out present timezone as shown below:

$ date

Also type the command below:

$ date +"%Z %z"
[root@unixcop ~]# date
Thu Sep 23 11:16:59 EDT 2021
[root@unixcop ~]# 
[root@unixcop ~]# date +"%Z %z"
EDT -0400
[root@unixcop ~]#

%Z : prints the alphabetic timezone .

%z prints the numeric timezone.

Note: You can read the formats of date command with date man page :

$ man date

Also you can likewise use timedatectl command

So It displays an info about the system including the timezone as shown below:

[root@unixcop ~]# timedatectl
               Local time: Thu 2021-09-23 11:17:46 EDT
           Universal time: Thu 2021-09-23 15:17:46 UTC
                 RTC time: Thu 2021-09-23 15:17:46
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[root@unixcop ~]# 

Try to search with grep command on time zone to only filter the timezone as below:

$ timedatectl | grep 'Time zone'

You can also check the list of timezones using timedatectl list-timezones command as shown:

$ timedatectl list-timezones

On Ubuntu based Systems you can know timezone by displaying the content of the file /etc/timezone using cat command as shown:

[root@unixcop ~]# cat /etc/timezone
America/New_York
[root@unixcop ~]#

On REHL/CentOS 7 and Fedora you can know timezone by displaying the content of file /etc/localtime which is a symbolic link to the timezone file under the directory /usr/share/zoneinfo/.

Also to change the timezone, create the symbolic link /etc/localtime to the your timezone under /usr/share/zoneinfo/

ln  -sf /usr/share/zoneinfo/zoneinfo /etc/localtime

-s : enables that you can create a symbolic link.

-f: removes the destination file.. which is /etc/localtime.

Also a hard link is created by default

To change the timezone to America/New_York run the command below:

$ ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

Check timezone using Geolocation

Use curl command to check the timezone using Geolocation as shown below.

$ curl https://ipapi.co/timezone;echo

Conclusion

You can see the use of same timezone in your System for various purposes. Timezone concept is more important when we are talking about a Cluster setup who’s nodes are basically lies on two different geographical region. It is important to sync the timezone between the nodes to form a Cluster.

I hope you understand what I have illustrated.

Thank you!!

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook