howtouselinux

3 ways to change time in Linux

Table of Contents

There are a few reasons why your computer’s time might be wrong. It could be because your computer’s BIOS is not set correctly, or because your computer is not syncing its time with an NTP server. To fix this, you can try setting your computer’s BIOS to the correct time, or syncing your computer’s time with an NTP server.

Procedure to change time in Linux

  1. Open the terminal.
  2. Type date and press Enter to see the current date and time.
  3. Type sudo date -s “YYYY-MM-DD HH:MM:SS” and press Enter to change the date and time. Replace YYYY-MM-DD HH:MM:SS with the actual date and time you want to set.
  4. The output will show the new date and time that has been set.
  5. You can also use the timedatectl command to change the date and time. Type sudo timedatectl set-time “YYYY-MM-DD HH:MM:SS” and press Enter.

 

Change time with BIOS in Linux

To set your computer’s BIOS to the correct time, you will need to enter the BIOS setup utility. This is usually done by pressing a key during bootup, such as F12 or Esc.

Once in the BIOS setup utility, look for the “Date” and “Time” settings. Set the date and time to the correct values, then save your changes and exit.

Change time with date command in Linux

The best way to change time in Linux is using date command.To set time, you can use the “-s” option with the date command. For example, to set the date to January 22nd, 2030 and the time to 23:59:59, you would type the following command: date -s “22 Jan 2030 23:59:59”

The date command can be used to do a few different things, such as displaying the current date and time, setting the date and time.

The date command has a few different format options that you can use. The most common format is “MMDDhhmmYYYY”. For example, to set the date to February 2nd, 2020 at 6pm, you would type the following command: date -s “Feb 02 18:00:00 2020”

The second most common format is “YYYYMMDD”. For example, to set the date to February 29th, 2020, you would type the following command: date -s “20200229”. You can also use the ISO 8601 standard date format. For example, to set the date to February 29th, 2020, you would type the following command: date -s “2020-02-29”

How to change the timezone in Linux?

To change the timezone in Linux, you can use the “timedatectl” command. For example, to set your timezone to America/New_York, you would type the following command: sudo timedatectl set-timezone America/New_York

How to Sync time with  ntp server in Linux

The ntp service is a daemon that runs on Linux systems and synchronizes the system time with an NTP server. This ensures that the system time is accurate even when the system is turned off. To use the ntp service, you will need to install the ntp package. Once installed, you can start the service by running “sudo service ntp start”. To configure the ntp service, you can edit the “/etc/ntp.conf” file.

To check if your computer’s NTP service is active, you can use the “timedatectl” command. For example, to check if the NTP service is active, you would type the following command: sudo timedatectl status | grep -i ntp

If the NTP service is active, you will see a line that says “NTP synchronized: yes”. If the NTP service is not active, you will see a line that says “NTP synchronized: no”.

To manually sync your computer’s time with an NTP server, you can use the “ntpdate” command. For example, to sync your computer’s time with the NTP server pool.ntp.org, you would type the following command: sudo ntpdate pool.ntp.org

David Cao
David Cao

Hey there! I am David, a Cloud & DevOps Enthusiast and 18 years of experience as a Linux engineer. I work with AWS, Git & GitHub, Linux, Python, Ansible, and Bash. I am a technical blogger and a Software Engineer, enjoy sharing my learning and contributing to open-source.