It is important to use the correct timezone in Linux systems, since many applications and processes use it as a reference. In most cases, the system time zone is set during installation but it can be changed later on also. In this article, we will look at how to set or change Timezone in Ubuntu.
How to Set or Change Timezone in Ubuntu
Here are the steps to set or change timezone in Ubuntu. We will use timedatectl tool to change system time zone.
Check Current Timezone
First, we will check our current timezone by simply entering timedatectl command without any options.
$ timedatectl
You will see the following output.
Local time: Tue 2019-12-03 16:30:44 UTC Universal time: Tue 2019-12-03 16:30:44 UTC RTC time: Tue 2019-12-03 16:30:44 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: no systemd-timesyncd.service active: yes RTC in local TZ: no
In most Linux systems, the default time zone is set to UTC, as you can see above.
Also read : How to Implement SSL/TLS in Apache Tomcat
Change Timezone
Before we set or change timezzone in Linux, we need to know the name of our timezone that we need to use. For this purpose, we will list the available timezones using the following command.
$ timedatectl list-timezones
You will see the following output.
...America/Montserrat
America/Nassau
America/New_York
...
Once you have found out the name of your time zone, you can set or change it with the following command.
$ sudo timedatectl set-timezone <time_zone_name>
For example, if you want to set time zone to New York, here is the command for it.
$ sudo timedatectl set-timezone America/New_York
Once again, let us check the current time zone to ensure that the changes have been applied correctly.
$ timedatectl Local time: Tue 2019-12-03 13:55:09 EST Universal time: Tue 2019-12-03 18:55:09 UTC RTC time: Tue 2019-12-03 18:02:16 Time zone: America/New_York (EST, -0500) System clock synchronized: no systemd-timesyncd.service active: yes RTC in local TZ: no
As you can see above, the system timezone has been updated to New York’s timezone.
That’s it. It is very easy to change system timezone in Linux using timedatectl command.
Also read : How to Extract data from JSON file in Python
Set timezone on Old Linux versions
If you are running an old Linux version, timedatectl may not be available on it. In such cases, you can simply symlink /etc/localtime to the timezone of your choice in /usr/share/localtime
Here is an example to create a symlink to New York timezone.
$ sudo ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
Once you have set the timezone, you can verify it with date command.
$ date
Also read : How to Install Laravel with NGINX
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.