DEV Community

Cover image for ๐Ÿ•’ Linux Time Configuration: date, timedatectl, NTP & More
SAHIL
SAHIL

Posted on

๐Ÿ•’ Linux Time Configuration: date, timedatectl, NTP & More

๐Ÿ“Œ Introduction
Keeping the correct time on a Linux system is essential for logging, system tasks (cron), authentication, backups, and more. In this post, we'll cover:

  • How to view and change system time
  • Tools like date, timedatectl, and hwclock
  • What NTP is and how to configure it
  • Important packages: chrony, ntp, and systemd-timesyncd
  • Date/time formats and timezone handling

๐Ÿ—“๏ธ 1. Working with date Command

โœ… View Current Date and Time:

date
Enter fullscreen mode Exit fullscreen mode

Example Output:

Thu Jul 17 10:42:15 IST 2025
Enter fullscreen mode Exit fullscreen mode

๐Ÿ› ๏ธ Set Date and Time Using date

๐Ÿ”ธ Option 1: Use -s (String Format โ€” Simple!)

sudo date -s "17 Jul 2025 12:30:00"
sudo date -s "12:00"
sudo date -s "2025-07-17"
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ธ Option 2: Use Numeric Format

sudo date 071712302025.30
# Format: MMDDhhmmYYYY.ss
Enter fullscreen mode Exit fullscreen mode

โœ… Verify change:

date
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  2. timedatectl: Systemd Time Manager

๐Ÿ” View Current Status

timedatectl
Enter fullscreen mode Exit fullscreen mode

โฑ๏ธ Set System Date and Time

sudo timedatectl set-time "2025-07-17 12:45:00"
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ Set Timezone

sudo timedatectl set-timezone Asia/Kolkata
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“œ List All Available Timezones

timedatectl list-timezones
timedatectl list-timezones | grep Europe
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”Œ Enable or Disable NTP Sync

sudo timedatectl set-ntp true
sudo timedatectl set-ntp false
Enter fullscreen mode Exit fullscreen mode

๐Ÿ•ฐ๏ธ 3. hwclock โ€” Hardware Clock

๐Ÿงพ Commands:

sudo hwclock --show
sudo hwclock --systohc
sudo hwclock --hctosys
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ 4. NTP (Network Time Protocol)

โ“ What is NTP?
A protocol that keeps system clocks in sync with global time servers (UTC-based). Important for clusters, servers, and security.

โŒ› Popular Tools for NTP

Tool Package Notes
ntpd ntp Classic, older NTP client/server
chronyd chrony Fast, modern replacement
systemd-timesyncd Built-in Lightweight, good for desktops

โš™๏ธ Chrony Setup (Recommended)

sudo dnf install chrony     # RHEL/CentOS
sudo apt install chrony     # Debian/Ubuntu
sudo systemctl enable --now chronyd
Enter fullscreen mode Exit fullscreen mode

Edit config:

sudo nano /etc/chrony.conf
Enter fullscreen mode Exit fullscreen mode
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
Enter fullscreen mode Exit fullscreen mode

Sync Immediately:

chronyc makestep
Enter fullscreen mode Exit fullscreen mode

Check Sync Sources:

chronyc sources -v
Enter fullscreen mode Exit fullscreen mode

๐Ÿงฉ systemd-timesyncd (For Minimal Setups)

sudo systemctl enable --now systemd-timesyncd
timedatectl status
Enter fullscreen mode Exit fullscreen mode

๐Ÿงพ 5. Date/Time Formatting Examples

Format Description
%Y Year
%m Month
%d Day
%H Hour
%M Minute
%S Second
date +"%Y-%m-%d %H:%M:%S"
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ 6. UTC vs Local Time

date -u
TZ='America/New_York' date
Enter fullscreen mode Exit fullscreen mode

๐Ÿงช 7. Troubleshooting Tips

journalctl -u chronyd
chronyc makestep
timedatectl status
Enter fullscreen mode Exit fullscreen mode

โœ… Summary Cheat Sheet

Task Command
View system time date
Set time manually (simple) sudo date -s "12:30"
Set full date/time sudo timedatectl set-time "YYYY-MM-DD HH:MM:SS"
View timezone list timedatectl list-timezones
Set timezone sudo timedatectl set-timezone Region/City
Enable NTP sync sudo timedatectl set-ntp true
Install and configure chrony sudo dnf install chrony
View hardware clock sudo hwclock --show

๐Ÿ’ฌ Final Thoughts
Whether you're setting up a home server or managing enterprise infrastructure, time accuracy is vital. Learning to use tools like timedatectl, date, and chrony helps ensure reliability across your systems.

Top comments (0)