How to modify the time in Ubuntu system

Reference article:

Three methods to modify the time of the Ubuntu system

On Ubuntu, you can use the following three methods to change the time: date command, timedatectl command and hwclock command.

  1. Use the date command:

    • Open a terminal.
    • Enter the following commands to modify the date and time:
      sudo date --set="YYYY-MM-DD HH:MM:SS"
      
      Among them, YYYY represents the year, MM represents the month, DD represents the date, HH represents the hour, MM represents the minute, and SS represents the second. Replace this with the actual date and time you want to set.
    • Enter the administrator password to confirm the modification.
  2. Use the timedatectl command:

    • Open a terminal.
    • Enter the following commands to modify the date and time:
      sudo timedatectl set-time "YYYY-MM-DD HH:MM:SS"
      
      Replace the date and time with the actual values ​​you want to set.
    • Enter the administrator password to confirm the modification.
  3. Use the hwclock command:

    • Open a terminal.
    • Enter the following command to change the time of the hardware clock:
      sudo hwclock --set "YYYY-MM-DD HH:MM:SS"
      
      Replace the date and time with the actual values ​​you want to set.
    • Enter the following command to synchronize the system clock with the hardware clock:
      sudo hwclock --hctosys
      
      This will update the system clock to match the hardware clock.
    • Enter the administrator password to confirm the modification.

Note that editing the time may require administrator privileges. Make sure to enter the correct password when executing the command, and be careful to modify the time to avoid potential problems.

Guess you like

Origin blog.csdn.net/linux_tcpdump/article/details/131500898