How to Set the Date and Time on Linux
Linux is an operating system that’s widely used in the world of computing, powering servers, desktops, laptops, and embedded systems. Linux allows you to set the date and time easily and efficiently. In this article, we will explore how to set the date and time on Linux.
Before moving on to the steps, we should know that there are two clocks on Linux. One is hardware clock, which is also known as real-time clock, and the other is software clock. The software clock is used by the operating system, while the hardware clock is used by the BIOS.
Setting the Date and Time
There are different ways to set the date and time on Linux. Here are two of the most popular methods:
Method 1: Using the date Command
The date command is a simple tool that can be used to view and change the system date and time. Here’s how to set the date and time using this command:
- Open a terminal on your Linux computer.
- Type the following command to set the system date and time:
“`
sudo date –set=”YYYY-MM-DD HH:MM:SS”
“`
Replace YYYY, MM and DD with the current year, month, and day, and replace HH, MM, and SS with the current hour, minute, and second.
For example, to set the system date to March 3, 2022, at 7:45 PM, you would enter the following command:
“`
sudo date –set=”2022-03-03 19:45:00″
“`
- Press Enter to execute the command. You may need to enter your system password.
- Once the command is executed, the date and time will be set on your Linux computer.
Method 2: Using the timedatectl Command
timedatectl is a command-line utility that allows you to change the system time and date as well as the time zone. Here’s how to use the timedatectl command on Linux:
- Open a terminal on your Linux computer.
- Type the following command to set the system date and time:
“`
sudo timedatectl set-time “YYYY-MM-DD HH:MM:SS”
“`
Replace YYYY, MM, and DD with the current year, month, and day, and replace HH, MM, and SS with the current hour, minute, and second.
For example, to set the system time to March 3, 2022, at 7:45 PM, you would enter the following command:
“`
sudo timedatectl set-time “2022-03-03 19:45:00”
“`
- Press Enter to execute the command. You may need to enter your system password.
- Once the command is executed, the date and time will be set on your Linux computer.
Setting the Timezone
The timezone on Linux can be set using the timedatectl command. Here’s how to set the timezone:
- Open a terminal on your Linux computer.
- Type the following command to set the timezone:
“`
sudo timedatectl set-timezone TIMEZONE
“`
Replace TIMEZONE with the name of the timezone you want to set. For example, if you want to set the timezone to New York, you would enter the following command:
“`
sudo timedatectl set-timezone America/New_York
“`
- Press Enter to execute the command. You may need to enter your system password.
- Once the command is executed, the timezone will be set on your Linux computer.