Thursday, May 16, 2024
66
rated 0 times [  66] [ 0]  / answers: 1 / hits: 183912  / 1 Year ago, sat, january 14, 2023, 10:16:23

Is there such command for changing the System clock's date and time?



For example:



The current date and time is January 1, 1970 22:30:59:980 where 59 and 980 refers to the seconds and millisecods respectively



And I want to change it to January 2, 1971 23:31:59:990



Is there a command for this?


More From » command-line

 Answers
6

To set the time in Ubuntu from the terminal, you can use the following command:


sudo date new_date_time_string

where new_date_time_string has to follow the format MMDDhhmmyyyy.ss which is described below:



  • MM is a two digit month, between 01 to 12

  • DD is a two digit day, between 01 and 31, with the regular rules for days according to month and year applying

  • hh is two digit hour, using the 24-hour period so it is between 00 and 23

  • mm is two digit minute, between 00 and 59

  • yyyy is the year; it can be two digit or four digit

  • ss is two digit seconds. Notice the period . before the ss.


Source: Manage Time in Ubuntu Through Command Line.


So, in your particular case, you can use:


sudo date 010224311971.59

Or, you can use:


sudo date --set="1971-01-02 23:31:59.990"  && date --rfc-3339=ns

which is exactly what you asked.


Source:



[#29548] Monday, January 16, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nguai

Total Points: 216
Total Questions: 108
Total Answers: 116

Location: Hong Kong
Member since Thu, Dec 16, 2021
2 Years ago
nguai questions
Thu, Mar 9, 23, 19:37, 1 Year ago
Thu, Apr 27, 23, 02:41, 1 Year ago
Tue, Jan 17, 23, 20:59, 1 Year ago
Fri, Oct 8, 21, 19:38, 3 Years ago
Tue, Oct 5, 21, 15:24, 3 Years ago
;