The system clock synchronizes automatically to the internet time server, which ensures the current time and date are accurate. Like other operating systems, Linux also allows the users to change the default date and time, either previous/future, as per user choice.
It is usually performed when the system’s default date and time become inaccurate. This is because the correct date and time play an important role in automating the task and connecting the services over the network.
This guide lists down all the best approaches for setting the date and time on the Linux operating system:
- Method 1: Using the “date” Command
- Method 2: Using the “timedatectl” Command
- Method 3: Using the “hwclock” Command
- Method 4: Using the “ntpdate” Command
- Method 5: Using the “Date&Time” Option (GUI)
Prerequisites: Deactivate Time Synchronization
Before moving on to the practical implementation, deactivate the time synchronization on the host. Because without its deactivation, the system will always print the default date and erase the manual date:
$ sudo timedatectl set-ntp false
The “ntp” synchronization is disabled now.
Method 1: Using the “date” Command
The “date” is the built-in command line utility that displays and sets the date of the Linux operating system in different formats. It requires the root user privileges in the form of a “sudo” command to perform this task:
The “date” command follows this basic syntax for setting date and time:
$ date -s or --set="YYYY-MM-DD hh:mm:ss"
The “set” is used as a command to set the new date and time. While the typed format characters are listed below:
|Date Format Characters||Time Format Characters|
|YYYY: Denotes the “year”||hh: Specifies the “hours”|
|MM: Shows the “months”||mm: Shows the “minutes”|
|DD: Identifies the day of the month||ss: Displays the “seconds”|
Example 1: Set a New Date and Time
The “date” command supports the “-s or set” flag to set the new date and time of the system in the following way:
$ sudo date --set="Wed Dec 07 15:23:34 EST 2022"
The new date and time of the current system has been set.
Example 2: Set Date in “Year:Month:Day” Format
The “date” command allows the user to set the new date in the “%Y(year)%m(month)%d(day)” format via the “+(plus)” sign with “date” command in this way:
$ sudo date +%Y:%m:%d --set "20240209"
The date “2024(year):02(month):09(day)” has been set.
Example 3: Set Time With “AM/PM” Notation
To set the time in either the AM or the PM notation, use the “%p(equivalent to am/pm)” and the “%T(specify time “hh:mm:ss”)” flag with the “date” command:
$ sudo date +"%T%p" -s "9:20:40AM"
The current system new “time” “09:20:40AM” has been adjusted.
Method 2: Using the “timedatectl” Command
The “timedatectl” command works on the “systemd” based Linux distributions to query and customize the system clock settings and enable/disable the time synchronization services.
The basic syntax is written below to change the default date and time of the system via the “timedatectl” command:
$ sudo timedatectl set-time “YYYY-MM-DD” #Change Current Date Only $ sudo timedatectl set-time “hh:mm:ss” #Change Current Time Only $ sudo timedatectl set-time "YYYY-MM-DD hh:mm:ss" #Change both Date and Time
The “timedatectl” command uses the “set-time” keyword to set the manual date and time of the operating system.
Example 1: Set a New Date
To set the new date, only use the “timedatectl” command with the “set-time” keyword following the “year:month:day” format:
$ sudo timedatectl set-time “2024-12-25”
The new date “2023-12-25” has been successfully set.
Example 2: Set a New Time
Specfiy the “hh:mm:ss” time format to modify the default time of the system in the following way:
$ sudo timedatectl set-time “06:25:30”
The new time of the system has been set.
Example 3: Change Date and Time(Both)
To change both date and time at the same time using the “timedatectl” utility using the below-mentioned command:
$ sudo timedatectl set-time “2023-03-01 07:15:24”
The error-free output confirms that both default date and time has been changed.
Method 3: Using the “hwclock” Command
The “hwclock” clock refers to the “hardware clock” utility that displays the current time, sets the hardware clock to system time, and sets the hardware clock at the specified time.
The generalized syntax of “hwclock” to set a new date and time is:
$ hwclock --set --date="YYYY-MM-DD hh:mm:ss"
The above syntax parameters are the same as the “date” command.
Example 1: Change the Current Date
Execute the “hwclock” command to set the new date and time like “March 3rd, 2024” followed by the time “08:05:02”:
$ sudo hwclock --set --date="2024-03-03"
Example 2: Change the Current Time
The “date” and “set” keyword is also used with the “hwclock” command to set the time i,e “04:30:40”:
$ sudo hwclock --set --date="04:30:40"
Now the system current time is “04:30:40”.
Method 4: Using the “ntpdate” Command
The “ntpdate” is an external command line tool that is utilized for synchronizing the correct date and time of the system by using the NTP servers. The most commonly used NTP server is the “ntp.pool.org”. It is the default time server for most Linux distributions.
Install “ntpdate” Command
First install the “ntpdate” command in the desired Linux distributions using default package managers:
$ sudo yum install ntpdate # For RHEL/CentOS $ sudo dnf insatll ntpdate # For Fedora $ sudo apt insatll ntpdate # For Ubuntu/Debian
The “ntpdate” has been successfully installed.
Synchronize Correct Date and Time
Specfiy the “NTP” server name “pool.ntp.org” with the “ntpdate” command having root user privileges i.e “sudo” to perform the time synchronization:
$ sudo ntpdate pool.ntp.org
The default date and time of the system have been synchronized with the “pool.nto.org” server.
Method 5: Using the “date” Option (GUI)
The graphical user interface also provides an easy and straightforward method to manually set the date and time in the Linux system. Follow the essential steps to perform this task.
Step 1: Navigate to System Settings
Open the “Settings” tools to access the “Date & Time” section from its menu. Click on the “Date & Time” option that displays the current date and time i.e. “1 March 2023. 06:57” in front of it:
Step 2: Set Date and Time
The “Date & Time” window is opened using the highlighted section “up/down-arrow keys” to set the new date and time that is “6 April 2025, 07:36” in this scenario:
Step 3: Verify the New Date and Time
The new date and time have been set and displayed in front of “Date & Time” option like this:
The above window is also beneficial to change the default “Time Format” and “Time Zone”.
In Linux, to set the manual date and time of the system, use the “date”, “timedatectl”, “hwclock”, and “ntpdate” command line utilities. All of these utilities provide a simple syntax to perform this job. This task can also be done using the “Date & Time” option provided by the graphical user interface.
This post has listed all possible methods to set the date and time on Linux.