Linux Set Date and Time From a Command Prompt

Q. How can I set the system date and time from the command prompt (bash shell)? I don't have GUI installed and I am login over ssh session.

A. Use date command to display the current date and time or set the system date / time over ssh session.

This is useful if the Linux server time and/or date is wrong, and you need to set it to new values from the shell prompt.

You must login as root user to use date command.

Linux Set Date

Use the following syntax to set new data and time:
date set="STRING"

For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"

Linux Set Time

To set time use the following syntax:
# date +%T -s "10:13:13"
Where,

  • 10: Hour (hh)
  • 13: Minute (mm)
  • 30: Second (ss)

Use %p locale’s equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"

See also:

You can also set new timzone using this mini-howto.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 31 comments… read them below or add one }

1 Johan Dalevi 04.08.07 at 8:51 pm

Found out i had to set the date like this:
# date -s 2007.04.08-22:46+0000

2 mani 12.12.07 at 6:57 am

How can I set the proxy setting from the command prompt (bash shell)?

3 raju 01.10.08 at 7:25 am

Just This code is ultimate.It is simple and worth full.Thank you very much providing help to people.

4 kiran 03.08.08 at 4:26 am

It Work’s Thanks a Lot,

Kiran.

5 djeikyb 05.21.08 at 12:18 am

mani– run:
export http_proxy=’http://10.10.1.2:3128′

6 R.K.Majhi 06.24.08 at 1:29 pm

It helped me to change the server timings without any difficulty. I tried to get help from the command prompt but it didn’t render anything. Thanks for the solution.

7 Mohit Guleria 06.27.08 at 5:08 pm

Do check and sync hardware clock with:
# hwclock –show
# hwclock –systohc

8 Paolo 07.24.08 at 12:16 pm

This configuration string is exactly what i’m searching for. thanks.

9 job wakhungu 07.30.08 at 4:49 pm

i had to set the date by using {date -s “wed jul 30 19:41:00 BST 2008″} while at the root.

10 gujubhai 08.13.08 at 9:43 am

hey thanks a million,
this worked right the first time…

was wondering how to do it untill i found ur site…

keep up the good work…very neat for freshers to *nix

cheers

11 rostiarso 08.21.08 at 3:41 am

You could also simplify the format of input date as example below
date +%Y%m%d -s "20080817" (set new date to August 17, 2008) without typing full date format

12 Abdussami 10.26.08 at 11:35 am

Just amazing command… & help.. gr88 work.. keep it up.

May allah bless you…

13 marius 10.27.08 at 7:07 pm

thank you!!!!

i have fedora 9 i can not change the time using his time control application. he ask for my root password, and then he says that it is not correct…. crazy program :)

the man page of date did not showed me any example, i what i tried was not accepted.

thank you.

14 D 11.02.08 at 10:09 am

Thanks

15 pramod 11.07.08 at 4:11 am

this is gr8
I synced HW clk with sysstem clock also.
But after reboot the time is again changed

16 Frank Haynes 11.27.08 at 6:35 pm

The man page for the ‘date’ command is WORTHLESS.

Now that I read here how to format the input string in order to set the clock my life is good. THANK YOU!

17 saiph savage 11.28.08 at 3:22 pm

thanks !
very nice article, super easy :)

18 Venu Reddy 12.18.08 at 6:35 am

Thanks brother,
It has worked. Great work…!

19 Neelesh 12.22.08 at 2:04 pm

date set=”2 OCT 2006 18:00:00″

it is doesn’t work.
I have to change my linux system time./ Right now it is shows correct time on my machine but when i open my gmail account it’s shows wrong time of my emails.Due to it’s system time.

Any idea?

20 Dennis Quek 01.21.09 at 5:10 am

Anyone has ideas how to set Dates 1 day or 2 dates ago. What about setting it +2 hours in advance etc ?

21 Nickalf 02.11.09 at 7:49 pm

Hi All,

The problem I’m having is, the time/date changes at the time I do it, but doesn’t hold after a reboot – how can i lock it into the Server’s clock..

Neelesh – Try date -s ”2 OCT 2006 18:00:00″ instead

Nickalf. . .

22 Adnan 02.17.09 at 9:01 am

Thanx alot.. working properly

23 Bimlesh sharma 02.24.09 at 11:28 am

date -s ”2 OCT 2006 18:00:00″ is set for the time being. Need o set CMOS clock using “hwclock” command. That will be right solution.

24 C Chavez 03.03.09 at 9:41 pm

SIDE NOTE RE: SETTING HWCLOCK

format should be:

# hwclock –systohc

(note double -)

CHeers!

25 George 03.18.09 at 5:57 am

Thanks alot

THis has worked like yesterday

Keep up the good work.

Regards,

George Ndung’u
IT & Logistics Manager
LSHS

26 Ajay Shaldiwal 03.20.09 at 6:30 am

Dear Sir,

Thanks a Lot.

Ajay

27 Mister D 05.05.09 at 9:17 am

Thanks!!!

28 Gopal 05.05.09 at 5:59 pm

One more thank you for your simple explanation and great example. I couldn’t figure out the format from reading the date man page.

29 Zahid 05.14.09 at 12:26 pm

Nice

30 cat 06.01.09 at 12:12 pm

Thank you so much, it works.

31 en 06.13.09 at 9:14 am

Thank you! This information was very helpful.

Some of the examples you have presented here would be hard to derive from the date man page.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , , , , , , , , ,

Previous post: Warning: Remote Host Identification Has Changed error and solution

Next post: BASH Shell change the color of my shell prompt under Linux or UNIX