To set the date and time on a Linux system from the command prompt, you can use the date
command with the -s
option followed by the desired date and time in the format YYYYMMDDhhmm.ss
.
For example, to set the date and time to April 1, 2021 at 12:30:00, you can use the following command:
date -s "202104011230.00"
This will set the date and time to the specified value.
It's important to note that you may need to have root privileges to use the date
command to set the date and time.
You can also use the timedatectl
command to set the date and time on a system that uses the systemd
init system. For example:
timedatectl set-time "20210401 12:30:00"
This will set the date and time to the specified value.
For more information about using the date
command and the timedatectl
command, you can refer to the date
manual page and the timedatectl
manual page. For example:
man date
man timedatectl
It's also important to note that you may need to restart some services or applications for the changes to take effect.