In Unix-like operating systems, the date and time can be set using the date
command. To set the date and time, you need to have superuser privileges.
Here’s the basic syntax for setting the date and time using the date
command:
sudo date --set="YYYY-MM-DD HH:MM:SS"
Replace YYYY-MM-DD
with the desired year, month, and day, and HH:MM:SS
with the desired hour, minute, and second.
For example, to set the date and time to January 1, 2022 at 12:00:00, you would run the following command:
sudo date --set="2022-01-01 12:00:00"
Note that the time zone can also be set using the TZ
environment variable. For example, to set the time zone to Pacific Standard Time, you would run the following command:
sudo TZ=PST8PDT date
It’s important to use the correct time zone identifier, as different systems may use different time zone names. You can use the timedatectl
command to see the list of available time zones on your system.