Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

up vote 17 down vote accepted

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: http://serverfault.com/a/338395/181186.

share|improve this answer
    
what is the actual format of the string date? –  Abel Melquiades Callejo Sep 8 '13 at 7:18
    
does that mean the accuracy can only be limited to seconds? –  Abel Melquiades Callejo Sep 8 '13 at 7:22
    
@AbelMelquiadesCallejo See my new edits. –  Radu Rădeanu Sep 8 '13 at 7:34
1  
Could someone explain? hh is between 00 and 23, but OP and this answer show it being set to 24. –  Carl H Apr 30 at 8:10
    
@CarlH Great catch on that! See the new edits –  Abel Melquiades Callejo Apr 30 at 15:52

You can use date command to change time and you need sudo permission to do it, an example to set date as 27 June 2014 and time as 1:17 am is :-

sudo date --set "27 Jun 2014 1:17:00"
share|improve this answer

The easy way:

ntpdate -s ntp.ubuntu.com

To change the timezone:

dpkg-reconfigure tzdata

Probably you need sudo.

share|improve this answer
    
Which NTP server is going to set the time to January 1971, I wonder. –  muru Apr 30 at 15:53
    
Is your server connected to internet? Check official documentation at help.ubuntu.com/lts/serverguide/NTP.html –  Ninecols May 12 at 14:43
sudo date --set="Mon Feb 16 08:49:56 IST 2015"

That would be correct statement in UBUNTU 14.04.

share|improve this answer
1  
For everyone in the IST timezone only? Does the other answer not work for you? –  Xen2050 Feb 16 at 9:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.