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.
-
Use the date command:
- Open a terminal.
- Enter the following commands to modify the date and time:
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.sudo date --set="YYYY-MM-DD HH:MM:SS"
- Enter the administrator password to confirm the modification.
-
Use the timedatectl command:
- Open a terminal.
- Enter the following commands to modify the date and time:
Replace the date and time with the actual values you want to set.sudo timedatectl set-time "YYYY-MM-DD HH:MM:SS"
- Enter the administrator password to confirm the modification.
-
Use the hwclock command:
- Open a terminal.
- Enter the following command to change the time of the hardware clock:
Replace the date and time with the actual values you want to set.sudo hwclock --set "YYYY-MM-DD HH:MM:SS"
- Enter the following command to synchronize the system clock with the hardware clock:
This will update the system clock to match the hardware clock.sudo hwclock --hctosys
- 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.