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)