The timedatectl command is a powerful tool that can be used to view and change the system’s time and date settings in Ubuntu. It is a part of the systemd system and service manager, and it is a replacement for the old date command.
To use timedatectl, you need to be logged in as a root user or have sudo privileges. Once you are logged in, open a terminal window and type the following command:
timedatectlThis will display the current time and date settings for your system, including the timezone.
To list all of the available timezones, you can use the following command:
timedatectl list-timezonesYou can use grep to find your timezone.
timedatectl list-timezones | grep -i <city name>results for timedatectl list-timezones | grep -i paris:
Europe/ParisTo set the timezone, you can use the following command:
timedatectl set-timezone <timezone>For example, to set the timezone to America/New York, you would use the following command:
timedatectl set-timezone America/New_YorkOnce you have set the timezone, you can use the following command to verify that the change has been made:
timedatectlThe output of this command should now show the new timezone. e.g. before:
Local time: Wed 2023-09-13 00:01:57 UTC Universal time: Wed 2023-09-13 00:01:57 UTC RTC time: Wed 2023-09-13 00:01:57 Time zone: Etc/UTC (UTC, +0000)System clock synchronized: yes NTP service: active RTC in local TZ: noAfter:
Local time: Tue 2023-09-12 20:02:10 EDT Universal time: Wed 2023-09-13 00:02:10 UTC RTC time: Wed 2023-09-13 00:02:10 Time zone: America/New_York (EDT, -0400)System clock synchronized: yes NTP service: active RTC in local TZ: noIn addition to setting the timezone, you can also use timedatectl to enable or disable NTP updates. NTP (Network Time Protocol) is a protocol used to synchronize the clocks of computers over a network. To enable NTP updates, you can use the following command:
timedatectl set-ntp trueTo disable NTP updates, you can use the following command:
timedatectl set-ntp falseTo verify that NTP updates are enabled or disabled, you can use the following command:
timedatectl statusThe output of this command should show the status of NTP updates.
Here are some additional things to keep in mind when using timedatectl:
-
The timedatectl command can be used to change the timezone for the entire system, or for a specific user.
-
If you are changing the timezone for the entire system, you need to restart the system for the changes to take effect.
-
If you are changing the timezone for a specific user, you need to log out and log back in for the changes to take effect.
-
NTP updates are usually enabled by default in Ubuntu. However, if you have disabled them, you can enable them using the timedatectl command.
I hope this article has been helpful in explaining how to use timedatectl to set the timezone in Ubuntu and enable NTP updates. If you have any questions, please feel free to ask in the comments :).