I'm in need to temporarily change the date to debug one script and I run inti unexpected problem:

root@xxx:/# LC_ALL=C date
Wed Jan 31 17:09:02 EET 2018
root@xxx:/# LC_ALL=C date -s "2018-01-10 17:09:30"
Wed Jan 10 17:09:30 EET 2018
root@xxx:/# LC_ALL=C date
Wed Jan 31 17:09:28 EET 2018

note: I have a ru_RU locale, so I use LC_ALL=C for your convenience. Using the commands without LC_ALL change nothing.

I guessed that I do something wrong with syntax or reading man incorrectly, so I used instructions from this thread and it solved nothing. attempts to set hwclock to match date resulted in nothing:

root@xxx:/# LC_ALL=C hwclock --systohc
root@xxx:/# LC_ALL=C hwclock --show
Wed Jan 31 17:18:17 2018  .451473 seconds
root@xxx:/# man hwclock
root@xxx:/# hwclock --set --date='2011-08-14 16:45:05'
root@xxx:/# LC_ALL=C hwclock --show
Sun Aug 14 16:45:09 2011  .389008 seconds
root@xxx:/# LC_ALL=C date
Wed Jan 31 17:21:07 EET 2018

How can I change date?


root@xxx:/# cat /etc/lsb-release 

UPDATE for @Yaron

kovjr@xxx:~$ LC_ALL=C sudo date 120622432007.55
[sudo] password for kovjr: 
Thu Dec  6 22:43:55 EET 2007
kovjr@xxx:~$ LC_ALL=C date
Wed Jan 31 18:19:23 EET 2018
  • Is it regular ubuntu machine or ubuntu VM? – Yaron Jan 31 '18 at 16:28
  • 1
    it is a regular – kovalenko-alex Jan 31 '18 at 16:32

As described here:

View Time

To view the current date and time, the following command will be enough


Set Time

To change time means to set a new time. To set time in Ubuntu (or any Linux), just run the following command

sudo date newdatetimestring

where newdatetimestring has to follow the format nnddhhmmyyyy.ss which is described below

nn 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: your choice. I prefer to use four digit years whenever I can for better clarity and less confusion
ss is two digit seconds. Notice the period ‘.’ before the ss.

Let’s say you want to set your computer’s new time to December 6, 2007, 22:43:55, then you would use:

sudo date 120622432007.55


$ sudo date 120622432007.55
[sudo] password for xyz: 
Thu Dec  6 22:43:55 IST 2007
$ date
Thu Dec  6 22:43:56 IST 2007
  • it just doesn't stick: root@xxx:/# LC_ALL=C date 011017502018.00 \n Wed Jan 10 17:50:00 EET 2018 \n root@xxx:/# LC_ALL=C date \n Wed Jan 31 17:57:51 EET 2018 – kovalenko-alex Jan 31 '18 at 15:59
  • @kovalenko-alex - as you can see from the updated answer, it do work (tested on ubuntu 16.04) – Yaron Jan 31 '18 at 16:01
  • @kovalenko-alex - you forgot to execute sudo before the date command when you set the date – Yaron Jan 31 '18 at 16:04
  • are you sure you are reading what I post? commands are executed from root (sudo -i was used before) as is clearly visible from code. It doesn't stick. It also shows that any variant I tried did output the correct date as a result of command, but it failed on the second call (date without arguments). So, the commands are correct, rights are correct, but something interferes. I want some hints on where to find the origin of interference. – kovalenko-alex Jan 31 '18 at 16:10
  • @kovalenko-alex - comments aren't good place to hold logs, as it is very hard to read logs in comments. I missed the fact that you were running the command as root. Would you try to execute the two commands as descries in my answer (see example part of the answer)? – Yaron Jan 31 '18 at 16:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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