How to change the time and date in Linux?
In Linux, you can use the following command to modify the date and time:
- The “date” command is used to display and set the date and time of the system.
- To display the current date and time, simply run the date command.
- To set the date and time, use the following format with the date command: date -s “YYYY-MM-DD HH:MM:SS”, where 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. For example, to set the date to October 1st, 2021 and the time to 09:30:00, run date -s “2021-10-01 09:30:00”.
- The hwclock command is used to display and set the hardware clock, also known as RTC or real-time clock.
- To display the date and time of the current hardware clock, use the hwclock command.
- To set the date and time on the hardware clock, use the following format to run the hwclock command: hwclock –set –date “YYYY-MM-DD HH:MM:SS” where YYYY represents the year, MM represents the month, DD represents the date, HH represents the hour, MM represents the minutes, and SS represents the seconds. For example, to set the hardware clock to October 1, 2021 at 09:30:00, run hwclock –set –date “2021-10-01 09:30:00”.
Please note that modifying the date and time usually requires root or administrator privileges.