How to Set Date and Time on Linux: 3 Easy Methods

Written by

Reviewed by

Last updated: July 4, 2024

Expert verified

SVG Image


To set date and time on Linux, try these three methods:

  1. Date Command: Use sudo date -s “YYYY-MM-DD HH:MM:SS” in the terminal to set the date and time directly.
  2. Timedatectl Command: Use sudo timedatectl set-time YYYY-MM-DD HH:MM:SS to manage and configure the system’s date and time settings.
  3. Utilizing GUI Tools: Open the GNOME Control Center, go to Settings > Date & Time, and either enable automatic synchronization or manually set the date and time.

Explore the article below to learn different methods to set date and time on Linux, and common errors that can occur.

Keeping your Linux system’s date and time accurate is essential for smooth operation. Tasks like backups, security logging, and network synchronization all depend on precise time settings. In this guide, I’ll show you how to display, change, and synchronize date and time, set your time zone, and troubleshoot common errors. You’ll find step-by-step instructions to ensure your system clock is always correct. By the end of this post, you’ll have the knowledge to maintain accurate time settings, improving your system’s reliability and performance.

Why Accurate Date and Time Settings Matter

Accurate date and time settings are crucial for your Linux system:

  • System Processes and Cron Jobs: Many tasks, like backups and system updates, rely on precise timing. If your clock is off, these tasks might not run when they should, causing delays or failures.
  • Security and Logging: Correct timestamps in logs are essential for tracking events and troubleshooting issues. Accurate time helps identify when security breaches occur and allows for proper incident analysis.
  • Network Synchronization: In a network, synchronized clocks are necessary for seamless communication between systems. Applications like databases and email servers need this to avoid data corruption and errors.
  • Data Consistency: Distributed systems require consistent time settings across all components to maintain data integrity. Incorrect time can lead to inconsistencies and unreliable transactions.
  • Application Performance: Many applications, especially those handling transactions or real-time data, depend on accurate time. Errors in time settings can slow down performance or cause applications to fail.

How to Display Date and Time in Linux?

Accurately checking the current date and time on a Linux system is crucial for system administration, troubleshooting, and ensuring synchronization across various services and applications. Two common methods to display date and time in Linux are using the date command and the timedatectl command.

1. Using the Date Command

The date command in Linux is a simple yet powerful utility that allows users to display the current date and time. It’s often used in scripts and for quick checks from the terminal.

  1. To use the date command, simply type date in the terminal and press Enter. 

The output will display the current date and time.

viewing current date and time
  1. To display the date and time in a specific format, you can use format specifiers. For instance, to display the date in YYYY-MM-DD format, use:
date +"%Y-%m-%d"

The output will be:

viewing date in specific format

2. Using Timedatectl

The timedatectl command is a part of the systemd suite, providing a comprehensive tool to query and change the system clock and its settings. It offers more detailed information and control compared to the date command.

  1. To check the current date and time using timedatectl, type the following command in the terminal:

The timedatectl output includes:

  • Local time: The current time in the local time zone.
  • Universal time: The current time in Coordinated Universal Time (UTC).
  • RTC time: The current time in the hardware Real-Time Clock (RTC).
  • Time zone: The configured time zone of the system.
  • System clock synchronized: Indicates if the system clock is synchronized with a time server.
  • NTP service: Shows whether the Network Time Protocol (NTP) service is active.
  • RTC in local TZ: Indicates if the hardware clock is set to the local time zone.
checking detailed view of time and date

How to Set Date and Time on Linux

To set the date and time on Linux, open your terminal and use the date command for direct adjustments by typing sudo date -s "YYYY-MM-DD HH:MM:SS". Alternatively, use the timedatectl command with sudo timedatectl set-time YYYY-MM-DD HH:MM:SS for more comprehensive control. For a user-friendly approach, go to the GNOME Control Center, navigate to Settings > Date & Time, and either enable automatic synchronization or manually set the date and time.

Here is the detailed step-by-step guide for each method to set date and time on Linux

1. Date Command

This Terminal method provides precise control and flexibility in setting the date and time on Linux, allowing advanced users to make specific time adjustments directly. Follow these steps:

  1. Open the Terminal by pressing Ctrl + Alt + T.
opening terminal 18
set date and time on linux
  1. To set the date and time using the Terminal, you can utilize the date command. Type the following command and press Enter:
date -s "YYYY-MM-DD HH:MM:SS"

Replace “YYYY-MM-DD” with the desired date in the format Year-Month-Day, and “HH:MM:SS” with the desired time in the format Hours:Minutes:Seconds.

changing date and time in linux
  1. Verify the changes by running the date command without any arguments.
verifying current date and time

2. Timedatectl Command

The timedatectl command is a part of the systemd suite and provides a comprehensive tool to manage and configure the system’s date and time settings. This command allows you to set the system clock, synchronize it with the hardware clock, and configure time synchronization services, such as NTP (Network Time Protocol).

  1. Open your terminal application to access the command line.
  2. Use the timedatectl set-time command followed by the desired date in YYYY-MM-DD format.
sudo timedatectl set-time 2024-06-27
setting desired date on the system
  1. Similarly, set the time using the HH:MM:SS format.
sudo timedatectl set-time 10:15:42
setting desired time on the system 1
  1. Confirm that the date and time have been updated.
checking detailed view of time and date 1

3. Utilizing GUI Tools

GUI tools offer a user-friendly interface for managing date and time settings, making it convenient for users to set the date and time accurately without complex commands or configurations. Follow these steps:

  1. Open the GNOME Control Center by clicking on the Activities button in the top-left corner of the screen.
opening gnome control center
  1. Searching for Settings and open it by clicking on it.
opening system settings 1
  1. In the Settings window, select Date & Time from the sidebar.
selecting date and tme from the settings
  1. Enable automatic time synchronization by toggling the switch for Automatic Date & Time and Automatic Time Zone.
enabling automatic date and time sync
  1. To set the date and time manually, disable the automatic synchronization and adjust the date and time fields accordingly.
setting date and time manually

How to Enable Automated Time Synchronization?

NTPD (Network Time Protocol Daemon) is a powerful and versatile time synchronization daemon that maintains the system time in synchronization with internet standard time servers. It ensures precise timekeeping, which is crucial for time-sensitive applications and processes.

  1. Install the NTP package by running the following command in the Terminal:
sudo apt-get install ntp
  1. Use the appropriate package manager for your Linux distribution if you’re not using Ubuntu-based systems.
installing ntp package in ubuntu
  1. Once the installation is complete, open the NTP configuration file using a text editor. For example:
sudo nano /etc/ntp.conf
  1. The command will open the NTP configuration file in a nano text editor.
opening ntp configuration file in nano editor
  1. Go to the site and copy the NTP server suitable for your region.
copying ntp servers
  1. Locate the pool directive and replace the default NTP servers with the ones suitable for your region. Save the changes and exit the text editor.
replacing default ntp servers with suitable ones
  1. Restart the NTP service for the new configuration to take effect. Use the following command:
sudo service ntp restart
  1. NTP will synchronize your system’s time with the configured NTP servers, ensuring accurate timekeeping.
restarting ntp service

How to Set the Time Zone in Linux

Setting the correct time zone on your Linux system is important for accurate timekeeping and proper functioning of scheduled tasks. Here’s a simple guide to help you set the time zone.

  1. Start by opening your Terminal application. Before changing the time zone, let’s see what the current setting is. Type the following command and press Enter:

Look for the line that says Time zone:. It shows your current time zone.

viewing current time settings 2
  1. To find the correct time zone for your location, list all available time zones by typing:
timedatectl list-timezones

This command will display a long list of time zones. You can scroll through them to find the one that matches your location. 

listing all available time zones
  1. Alternatively, you can use grep to narrow down the search. For example, to find time zones related to “America”, use:
timedatectl list-timezones | grep America
listing time zones of specific region
  1. Once you’ve found the correct time zone, set it using the following command. 
sudo timedatectl set-timezone Region/City

Replace Region/City with your chosen time zone.

setting the desired time zone
  1. To make sure the time zone has been updated, check the settings again:

The Time zone: line should now show the new time zone you set.

verifying that the time zone has been changed

4 Common Errors When Setting Date and Time in Linux

You may encounter certain errors that can hinder setting dates and times in Linux systems. By being aware of these common errors and their potential solutions, you can effectively set the date and time on your Linux system and ensure accurate time synchronization. Here are five common errors to be aware of:

  • Incorrect Date and Time Format: Incorrectly formatting the date and time can lead to errors when setting them in Linux. Ensure you follow the specified format, such as YYYY-MM-DD for the date and HH:MM:SS for the time. Using the wrong format can result in invalid date or time entries and cause synchronization problems.
  • ⛔️ Insufficient Privileges: If you encounter an “Insufficient Privileges” error, try running the command with sudo to ensure you have the necessary permissions. Without proper privileges, you won’t be able to modify the system’s date and time settings.
  • 🌐 Network Time Synchronization Failure: When configuring NTP or using online time servers, a common error is a failure to synchronize with the time source. This can occur due to network connectivity issues or misconfigured NTP settings. Ensure your network connection is stable, and check your NTP configuration and firewall settings.
  • 🌎 Incorrect Time Zone: Setting an incorrect time zone can result in a time discrepancy between your system and the actual local time. It’s essential to select the correct time zone during the initial setup or adjust it afterward using the appropriate tools.

In Conclusion

I have guided you through managing date and time on your Linux system, including displaying time, changing time, synchronizing it, setting the time zone, and troubleshooting errors.

For deeper insights:

  • Discover how to set or change the time zone in Ubuntu, which helps you align your system’s time with your local time zone.
  • Learn to check system logs on Linux to troubleshoot and confirm changes in date and time settings.
  • Explore how to view Linux file timestamps to understand how file modification times are recorded and managed, ensuring accurate file system timekeeping.

Frequently Asked Questions

Can I synchronize the date and time across multiple Linux systems?

Absolutely! You can synchronize the date and time across multiple Linux systems using the Network Time Protocol (NTP). To achieve this, designate one system as the NTP server and configure the other systems as NTP clients. The NTP server acts as the time reference, and the clients periodically synchronize their clocks with the server. This ensures consistent timekeeping across your network, facilitating smooth operations, accurate logs, and coordinated activities.

Can I set a specific date and time for a future event in Linux?

Yes, Linux provides several methods to set a specific date and time for a future event. One approach is using the date command with the desired date and time values. For more complex scheduling needs, you can leverage the Cron system, which allows you to configure recurring or one-time tasks at precise moments. By utilizing these tools, you can automate critical processes, such as backups, system updates, or application launches, to occur exactly when needed, enhancing efficiency and reducing manual intervention.

Is there a way to synchronize the system clock with an external hardware time source?

Yes, Linux offers mechanisms to synchronize the system clock with external hardware time sources, guaranteeing highly accurate time references. For instance, you can employ Global Positioning System (GPS) receivers or atomic clocks connected to your Linux system. Specialized tools like NTP or PTP (Precision Time Protocol) enable the communication and synchronization between the system clock and these external time sources. By leveraging such hardware time sources, you can achieve precise timekeeping, which is essential for applications that require stringent time accuracy, scientific experiments, or systems where traceability is critical.



Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.



Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Effectively Use Linux Uname Command [9 Best Ways]

Next Post

How to Install OneDrive on Ubuntu [16 Simple Steps]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next