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, the change takes effect immediately. Long-running applications may need to be restarted to pick up the new timezone.
-
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 :).
Related Reading
- Ubuntu & Bash tutorial & basic utilities
- Bulk File Renaming on Linux: rename, vidir, fd
- Directory FileCount
- Essential Linux Commands for Daily Use
- Linux distribution info & kernel info
What Actually Breaks When the Timezone Is Wrong
“Immediate effect” is mostly true — but there’s a graveyard of things that silently keep the old timezone in memory until you poke them. Here’s what bites people:
Cron jobs. cron reads the timezone at startup. If you set the timezone and don’t restart the cron daemon, your 0 9 * * * job still fires at 9 AM UTC — or whatever the old zone was. Fix it:
sudo systemctl restart cronDocker containers. Containers inherit /etc/localtime from the host at start time. Running containers won’t notice the change. You need to restart them, or better yet, pass the timezone explicitly so you’re not relying on host inheritance at all:
docker run -e TZ=America/New_York your-imagePostgres and MySQL. Both cache timezone info when the service starts. Logs, NOW(), scheduled jobs — all potentially wrong until you restart the database service. This is the one that gets you at 2 AM when logs from “last night” appear to be from the future.
Your SSH session. If you’re logged in over SSH and you change the timezone, your current shell still has the old $TZ (or none) in its environment. Open a new session and it’ll pick up the system zone correctly.
The NTP Gotcha Nobody Warns You About
If timedatectl shows System clock synchronized: no and NTP service: active, the usual culprit is that systemd-timesyncd is fighting with another NTP client — chrony or ntpd — that got installed by something else. You can’t run two NTP daemons on the same host; they’ll both lose their minds.
Check what’s running:
systemctl status chronyd ntpd systemd-timesyncd 2>/dev/null | grep -E "Active:|●"Pick one, disable the other. For most Ubuntu servers systemd-timesyncd is fine unless you need high-precision sync — in which case, use chrony and disable timesyncd:
sudo systemctl disable --now systemd-timesyncdsudo apt install chronysudo systemctl enable --now chronyThen timedatectl show-timesync will report chrony as the sync source and synchronized: yes should come back within a minute or two.
Scripting Timezone Changes Across a Fleet
If you’re doing this on more than one box, you don’t want to type it interactively. Here’s the one-liner that works in Bash, Ansible shell tasks, cloud-init, or wherever you need it:
sudo timedatectl set-timezone "$(curl -sf https://ipapi.co/timezone)"That auto-detects the correct timezone from the server’s public IP — handy for freshly provisioned VMs where you know the geographic region but don’t want to hardcode it. Obviously don’t use this if the server is behind a VPN or the IP is misleading. And yes, check what data that endpoint returns before running it in prod. Trust but verify.