Linux date command not working

12

3

I can't seem to get the terminal command 'date' working. Here is an example of the commands I gave in terminal:

$ date
Wed Oct  7 17:17:38 EDT 2015
$ sudo date --set="20151007 18:17:00"
Wed Oct  7 18:17:00 EDT 2015
$ date
Wed Oct  7 17:18:11 EDT 2015

Is there something I need to change in the settings to be able to manually set the time? I've looking into disabling ntp but as far as I can tell it isn't something that needs to be disabled to be able to manually set time.

I've looked up all the possible formats of the date string, and none of them did the trick. Here are some of the ones I tried:

$ sudo date --set="2 OCT 2006 18:00:00"
$ sudo date +%Y%m%d -s "20081128"
$ sudo date 120622432007.55
$ sudo date --set="Sat Oct 10 10:10:10 EDT 2015"

I would appreciate any help. Thanks.

GeneralAsh

Posted 2015-10-08T13:49:11.490

Reputation: 401

2Are you possible running ntpd which resets your time to the one synchronized with a remote server? – nKn – 2015-10-08T16:16:18.753

Answers

18

It turns out I had to change time/date settings from automatic to manual in System Settings. As I am doing everything through ssh I could not do this in the gui settings, but the equivalent command on terminal is:

$ timedatectl set-ntp false

This disables the automatic time sync allowing me to set the time and date manually using the date command

GeneralAsh

Posted 2015-10-08T13:49:11.490

Reputation: 401

If @nKn re-phrases the suggestion into an official answer, it would be right for GeneralAsh to accept that answer so nKn gets proper reputation benefit. After all, nKn really did provide the right direction to look at. – TOOGAM – 2015-10-08T17:28:56.463

2

Look though the process list printed by

ps -ef

to see for likely culprits. These may include

  • ntpd
  • ntpdate
  • systemd-timesyncd
  • ...

In my case, I had to do

systemctl stop systemd-timesyncd

user7610

Posted 2015-10-08T13:49:11.490

Reputation: 336