Linux Set Date and Time From a Command Prompt

by on October 2, 2006 · 134 comments· LAST UPDATED April 23, 2014

in , ,

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. How can I set date under Linux operating systems?

Use the date command to display the current date and time or set the system date / time over ssh session. You can also run the date command from X terminal as root user.

Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsNone
Estimated completion time2m
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 Display Current Data and Time

Just type the date command:
$ date
Sample outputs:

Wed Apr 23 10:32:59 CDT 2014

Linux Display The Hardware Clock (RTC)

Type the following hwclock command to read the Hardware Clock and display the time on screen:
# hwclock -r
OR
# hwclock --show
OR show it in Coordinated Universal time (UTC):
# hwclock --show --utc
Sample outputs:

Wed 23 Apr 2014 10:36:23 AM CDT  -0.157239 seconds

Linux Set Date Command Example

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 Examples

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

  • 10: Hour (hh)
  • 13: Minute (mm)
  • 13: 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"

How do I set the Hardware Clock to the current System Time?

Use the following syntax:
# hwclock --systohc
OR
# hwclock -w

See also:
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 134 comments… read them below or add one }

1 Johan Dalevi April 8, 2007 at 8:51 pm

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

Reply

2 PRADEEP December 20, 2010 at 3:19 am

date -s “2 OCT 2006 18:00:00″

Reply

3 Edward biney August 2, 2014 at 3:55 pm

I want to set the date and time on my phone

Reply

4 mani December 12, 2007 at 6:57 am

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

Reply

5 raju January 10, 2008 at 7:25 am

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

Reply

6 kiran March 8, 2008 at 4:26 am

It Work’s Thanks a Lot,

Kiran.

Reply

7 varun September 8, 2010 at 12:26 pm

thank

Reply

8 djeikyb May 21, 2008 at 12:18 am

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

Reply

9 R.K.Majhi June 24, 2008 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.

Reply

10 Mohit Guleria June 27, 2008 at 5:08 pm

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

Reply

11 Maurice March 6, 2013 at 6:38 am

This is actually an important one!! Many thanks!

Reply

12 bryan April 23, 2014 at 2:05 pm

Thanks a ton Mohit, this is what i was looking for.

Reply

13 Paolo July 24, 2008 at 12:16 pm

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

Reply

14 job wakhungu July 30, 2008 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.

Reply

15 gujubhai August 13, 2008 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

Reply

16 rostiarso August 21, 2008 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

Reply

17 Abdussami October 26, 2008 at 11:35 am

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

May allah bless you…

Reply

18 marius October 27, 2008 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.

Reply

19 D November 2, 2008 at 10:09 am

Thanks

Reply

20 pramod November 7, 2008 at 4:11 am

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

Reply

21 Frank Haynes November 27, 2008 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!

Reply

22 saiph savage November 28, 2008 at 3:22 pm

thanks !
very nice article, super easy :)

Reply

23 Venu Reddy December 18, 2008 at 6:35 am

Thanks brother,
It has worked. Great work…!

Reply

24 Neelesh December 22, 2008 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?

Reply

25 Dennis Quek January 21, 2009 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 ?

Reply

26 Nickalf February 11, 2009 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. . .

Reply

27 Aman September 2, 2011 at 5:58 am

date –set=”2 sep 2011 11:27:20″

Reply

28 zia March 6, 2012 at 3:02 am

date -s ”2 OCT 2006 18:00:00″ Thanks it worked nicely oh! thanks

Reply

29 Adnan February 17, 2009 at 9:01 am

Thanx alot.. working properly

Reply

30 Bimlesh sharma February 24, 2009 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.

Reply

31 C Chavez March 3, 2009 at 9:41 pm

SIDE NOTE RE: SETTING HWCLOCK

format should be:

# hwclock –systohc

(note double -)

CHeers!

Reply

32 George March 18, 2009 at 5:57 am

Thanks alot

THis has worked like yesterday

Keep up the good work.

Regards,

George Ndung’u
IT & Logistics Manager
LSHS

Reply

33 Ajay Shaldiwal March 20, 2009 at 6:30 am

Dear Sir,

Thanks a Lot.

Ajay

Reply

34 Mister D May 5, 2009 at 9:17 am

Thanks!!!

Reply

35 Gopal May 5, 2009 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.

Reply

36 Zahid May 14, 2009 at 12:26 pm

Nice

Reply

37 cat June 1, 2009 at 12:12 pm

Thank you so much, it works.

Reply

38 en June 13, 2009 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.

Reply

39 Alan July 25, 2009 at 9:20 pm

I’ve just got a Datawind Ubisurfer and to set the date/time I had to type:
# date 07252208002009
25 July 2009 time 20:08

decodes as # date MMDDhhmmssYYYY

month day hour minutes seconds year
Thanks for other scripts they sent me in the right direction.
(This does come up as UTC whatever that is!)

Reply

40 herMz August 10, 2009 at 9:33 am

this is awesome.. thnks a lot..

Reply

41 Srini August 18, 2009 at 2:01 pm

Thanks…:)

Reply

42 FAHIM August 28, 2009 at 3:48 pm

Thanks its works….!!!

Reply

43 Dattatray Naik September 5, 2009 at 7:42 am

Thanks It Works.

Reply

44 vignesh September 6, 2009 at 7:03 am

Thanks for giving the command.. It’s very helpful for me.

Reply

45 Murugesh September 8, 2009 at 5:33 pm

info date Examples

Reply

46 thomas September 16, 2009 at 11:12 am

I am a layman in linux, but this sure helped me change my server time remotely.thankyou.

Reply

47 Kent September 25, 2009 at 9:03 am

Thanks C Chavez. I had a real time trying to get the hwclock to stop resetting. One line and BAM! Thanks again!

Reply

48 seth October 1, 2009 at 2:18 pm

THIS COMMAND DOESN’T WORK FOR OPEN BSD TO CHANGE THE DATE AND TIME

Reply

49 bharanitharan October 5, 2009 at 11:16 pm

Thanks Man :) it have worked for me ;-)

Reply

50 vinodanctk@gmail.com October 29, 2009 at 8:23 am

Dear sir,
Many Thanks for the help
Thanks

Reply

51 Mario Chamorro November 4, 2009 at 8:43 pm

Thank you , Murugesh . This is the first time I have ever found those ‘Info’ pages useful . I need this for a SQL script at work that needs to fetch data from 7 days ago . Murugesh to the rescue!

[ ~ ] date –date=’7 days ago’
Wed Oct 28 20:39:35 GMT 2009
[ ~ ]

— Mario

Reply

52 Jaxon November 9, 2009 at 8:35 am

It works, I have to check any time changing after restart the PC

Reply

53 sin December 9, 2009 at 6:31 pm

thanks it worked in first time… Really Thanks

Reply

54 Sana December 22, 2009 at 4:43 am

Thanks a lot for your help

Reply

55 nenopera January 18, 2010 at 9:11 am

$ sudo date +%Y%m%d%T -s “20081225 10:05:00″

[sudo] password for nenopera:
2008122510:05:00

$ date

Thu Dec 25 10:05:02 EST 2008

Reply

56 sumer February 8, 2010 at 7:19 am

`date +%G%m%d`-acb.txt
this is my current date format. I wants to set last day’s date instead of current. I try this from last week . Plz help me…………

Reply

57 shabbirali March 3, 2010 at 8:07 am

Date command is sweet and simple… :)
Man page is man!!!

Reply

58 sumer March 3, 2010 at 10:21 am

thanks guys….lov u ……..

Reply

59 ratish singh March 15, 2010 at 1:41 pm

How can i change my system date format on linux os?

Reply

60 vishal April 9, 2010 at 8:28 am

satish,

follow the steps
1.check date with date command
2.set date with date -s command
3.hwclock –systohc
4.hwclock –show

Vishal

Reply

61 sunraj June 9, 2010 at 1:28 pm

i like your commands. i am realy very impress

Reply

62 Indika April 23, 2010 at 5:09 pm

Hi this is really helpful guys….. thanks alot.

Reply

63 the birdie April 29, 2010 at 11:20 am

Thanks for passing on your knowledge.

Reply

64 luciano May 13, 2010 at 3:22 pm

# date set=”2 OCT 2006 18:00:00″ wrong!!!!
# date –set=”2 OCT 2006 18:00:00″

Reply

65 gayan June 11, 2010 at 3:45 am

thinks bro,

Reply

66 Vikas YAdav June 26, 2010 at 8:36 am

It was amazing……!!!!!!!!!

Reply

67 praV July 9, 2010 at 4:47 pm

THANKS

Reply

68 P.K.Ghosh July 29, 2010 at 6:57 am

Thank yo very much for sharing your knowledge
It’ really works fine
So… bye

Reply

69 kiran October 25, 2010 at 9:19 am

Thank you very much for giving me suggestion it is very usefull for me.

regards,
kiran ugale.

Reply

70 vijay November 9, 2010 at 4:28 am

Thanks a lot guys.. Everything worked.

Reply

71 William Simbota November 11, 2010 at 12:46 pm

I really appreciate. I think I will learn Linux at a fast pace with your assistance.

Reply

72 Naresh Babu December 21, 2010 at 12:26 pm

Information about date was very much helped me
Thanks

Reply

73 seachen January 13, 2011 at 5:36 pm

my vps time currently is as below:

[root@server25 ~]# date
Thu Jan 13 17:22:54 UTC 2011

how to change it to Thu Jan 14 01:25:54 MYT 2011

Reply

74 iskandar January 27, 2011 at 6:45 am

hai…
im have a problem about time on fedora
im use tht comman date, its change but if i restart my fedora is time will change
and wrong time after restart the komputer..
can help me?

Reply

75 iskandar January 27, 2011 at 7:40 am

now i understand how tht comman
tq friend..
now my fedora time is ok
the time is ok not change anymore..
Tq

Reply

76 micxz March 18, 2011 at 3:34 pm

not a big deal but small typo:
# 30: Second (ss)
should read 13 or in the example it should be :30

Reply

77 ankit maini March 22, 2011 at 1:13 pm

thanx :)

Reply

78 dani March 25, 2011 at 6:37 am

hello i want to change date separator… from / to .(dot) can u help me?
for example 23/03/2011 to 23.03.2011

Reply

79 Mohit G April 11, 2011 at 1:38 pm

View:
hwclock –show
date
ls -l /etc/localtime

Change:
To change the time use date followed by the month, day, hour, minute, and year all numeric and no spaces.
date 041106232011
hwclock –systohc
ln -sf /usr/share/zoneinfo/ /etc/localtime
vi /etc/sysconfig/clock (update timezone if redhat)
service ntpd restart

Check:
hwclock –show
date
ls -l /etc/localtime

Reply

80 mz May 24, 2011 at 9:41 am

it worked fine.
MZ

Reply

81 Jaat June 25, 2011 at 11:07 am

How to change duplex setting of lan card in Rhel5

Reply

82 Brent November 30, 2012 at 10:54 pm

On the same subject, how do I make non-dairy chocolate chip cookies?

Reply

83 sasi July 30, 2011 at 11:27 am

thankz

Reply

84 Erik Martis August 16, 2011 at 6:27 pm

Hi there,

thank you very much for the info …. works like a charm !!!
btw, once I set my system date and time correctly the use of the
“#hwclock –systohc” command rules ´em all too !!!

saludos!
eriku

Reply

85 prince f November 14, 2011 at 6:37 pm

thank you!

Reply

86 Soni Peterson December 23, 2011 at 3:49 am

To me, setting date and time in linux was really difficult and I was searching many documents / websites for this, and thank you very much for such comprehensive information for setting date and time. It helps me a lot.

Reply

87 surendra February 6, 2012 at 11:00 am

Thanks

Reply

88 sam March 6, 2012 at 10:32 am

not a big deal , just type :

#date 030613252012
03=March
06=Day
13=Hour
25=Min
2012=Year

That’s IT :)

Reply

89 prabhat March 27, 2012 at 4:01 pm

Hey guys i have tried each and every command to change my linux server time but after i try every command new time is displayed.But when i try to verify it by running date command it shows old time again.Plssss help me……..

Reply

90 sam March 28, 2012 at 9:30 am

my friend this one is working fine nor more no less :

[server#] date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

That’s IT :)

Reply

91 prabhat singh March 30, 2012 at 2:06 pm

after running this command , do i have to run any other command also?

Reply

92 sam April 3, 2012 at 9:28 am

nothing ;

just to make sure run :
#date

and see the date ;

Reply

93 sunay September 12, 2012 at 8:21 am

its easy to change date or time

Reply

94 Rao September 14, 2012 at 2:22 pm

Helped a lot…Thanks…

Reply

95 Ahamed Bauani October 11, 2012 at 8:28 pm

Thanks a lot for your help. But problem is there is no way to change the date if it is a VPS server :(

Reply

96 Sam October 12, 2012 at 5:31 pm

There is no different between actual server and virtual server ; you can use same command to change the date :

[VPS-server]# date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

Reply

97 Sam October 17, 2012 at 8:01 pm

Could you please tel me what distribution of linux that you are using ?

Reply

98 hapoint from bpoint October 31, 2012 at 12:58 pm

Thanks :)

Reply

99 dipesh March 15, 2013 at 3:47 pm

This is all awesome guys… many thanks

Reply

100 Ricky1990 April 8, 2013 at 2:11 pm

I really thank you so much because of my wordpress site display wrong date. After read this post, i’ve just changed it. Thanks so much again !

Reply

101 Milton May 11, 2013 at 7:33 am

Very helpful article.

Reply

102 yusuf October 19, 2013 at 11:48 am

HI,

how do i update time one linux machine to another machine via command ?

Reply

103 PRAVEEN November 19, 2013 at 2:10 am

I am getting below error while changing the time. can any one tell me how to resove it.
[cnems@SVT-CSM-01-M:/etc] date 1026140013
date: cannot set date: Operation not permitted
Sat Oct 26 14:00:00 BST 2013
[cnems@SVT-CSM-01-M:/etc]

Reply

104 Sam November 19, 2013 at 6:00 am

Please see the below sample :
[Server#] date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

Reply

105 sal November 22, 2013 at 7:19 pm

I have a VCX Connect box, a V7005, that accepts some of the commands on this page to change the date however the date is not actually changed. I’ve ran the following to no avail:

# DATE -S “22 NOV 2013 10:00:00″

This in different variations.

Might anyone know if there is another syntax associated with a 3com VCX box?

Reply

106 Sam November 24, 2013 at 5:56 am

have you tried the command that I have shared with you , and what was the output ?

Please see the below sample :
[Server#] date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

Reply

107 sal November 25, 2013 at 4:35 pm

Hi Sam

I managed to change the time on our VCX Linux box by entering one different variations of the command below. Not sure of the exact syntax but it goes something like this:

# DATE -SET “22 NOV 2013 10:00:00 PST″

It took a short while for the change to reflect on the box and all phones. Short while meaning a few hours.

Reply

108 Sam November 26, 2013 at 8:46 am

Dear ,

Could you please share with me the output of below command ?

# uname -a

Thanks

Reply

109 taufeeq January 12, 2014 at 6:04 am

not working says cannot set date:operation not permitted
what i can do?

Reply

110 Sam January 13, 2014 at 1:51 pm

Check , weather you are root user , or not .
normal user , cant change date .

date -s “YYYY-MM-DD HH:MM:SS”

Reply

111 taufeeq January 18, 2014 at 5:36 am

any trick to change?

Reply

112 sam January 18, 2014 at 7:43 pm

please send me the output of the below command :

# uname -a

Reply

113 taufeeq January 19, 2014 at 7:57 am

[mphs@mphs ~]$ date –set”4 JAN 2014 1:25:00″
date: unrecognized option ‘–set4 JAN 2014 1:25:00′
Try `date –help’ for more information.
[mphs@mphs ~]$ ^C
[mphs@mphs ~]$

Reply

114 Nix Craft January 19, 2014 at 10:57 am

You need to run date as root user:

sudo date --set="4 JAN 2014 13:25:00"

Reply

115 taufeeq January 19, 2014 at 4:08 pm

@Nix craft, its asking password but i don’t know the password and its impossible to know the password bcoz our system admin set its secretly

[mphs@mphs ~]$ sudo date –set=”4 JAN 2014 9:35:00″
[sudo] password for mphs:

Reply

116 Nix Craft January 19, 2014 at 4:55 pm

Try your own password. Also, you need to be root (sysadmin) or part of sysadmin group in /etc/sudoers to change system date. A normal user can not change system date or time due to security reasons.

Reply

117 taufeeq January 20, 2014 at 1:28 pm

ok got it thx for help

Reply

118 sam January 19, 2014 at 9:43 am

Mr. Taufeeq

here is my Skype ID :

mos3535

regards
mosleh

Reply

119 taufeeq January 19, 2014 at 4:04 pm

here is out for # uname -a

[mphs@mphs ~]$ uname -a
Linux mphs 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686 i686 i386 GNU/Linux
[mphs@mphs ~]$

Reply

120 sam January 19, 2014 at 8:37 pm

can also please run the below command :

# python -c ‘import platform ; print platform.dist()[0]’

and send the output here .

Skype : mos3535

Reply

121 taufeeq January 20, 2014 at 4:09 am

[mphs@mphs ~]$ python -c ‘import platform ; print platform.dist[0]’
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘function’ object is unsubscriptable
[mphs@mphs ~]$

sorry bro m not on skype

Reply

122 sam January 20, 2014 at 10:47 am

please as I told you , try to change date by supper user like root user:

# su –

if it ask you for password , you should know root password
if not , please create password for root like this :

# passwd root

Reply

123 Maurice March 6, 2014 at 9:17 pm

It even worked on the OLPC XO1

Reply

124 evhol June 3, 2014 at 6:41 am

thanks

Reply

125 Ajit June 6, 2014 at 5:47 pm

Thanks a lot.

Reply

126 kishan June 17, 2014 at 5:39 am

hello guys ..how to install VLC player in fedora 14 64bit

Reply

127 Matt July 1, 2014 at 3:49 pm

when I use:

date +%T -s “10:13:13″

or

date –set=”10:13:13″ the time is reset to 00:00:00.

Is there a solution to this?

Reply

128 sam July 2, 2014 at 7:02 am

To do what ?
use the command below to change back the date and time :

# date -s “YYYY-MM-DD HH:MM:SS”

Reply

129 Fela August 12, 2014 at 1:09 pm

thanks for sharing

Reply

130 Imad September 6, 2014 at 9:48 am

Really helped me.
thanks for sharing..

Reply

131 Narayana Reddy September 19, 2014 at 11:37 am

Even though if i set the system time using the command “date -s ” ” when i restart it again showing the old time y? is it the problem of c-mos battery or is there any other command to set time .

Reply

132 Fela October 9, 2014 at 12:17 pm

Hi Naraya,
I would advice you to check the cmos, that is most likely the biggest problem.
Before you sort that out; after setting the date using the command #date –set = “STRING”, remember to follow with the use of command # hwclock –systohc

Reply

133 vsj October 8, 2014 at 2:01 am

it works thanks

Reply

134 Gunasekar October 29, 2014 at 1:21 pm

I am trying to change the time from EDT to PDT
I have tried preety much everything still doent work.

i have changed
:[/etc/sysconfig]# ls -l /etc/localtime
lrwxrwxrwx 1 root root 37 Oct 28 15:48 /etc/localtime -> /usr/share/zoneinfo/America/Vancouver
i have updated /etc/sysconfig/clock with Vancouver
but when i run service ntpd restart , i get
Shutting down ntpd: [FAILED]
Starting ntpd: [ OK ]

—————————————————————
still shows the Eastern time.. :(
[/etc/sysconfig]# date
Wed Oct 29 09:20:40 EDT 2014

Reply

Leave a Comment

Tagged as: , ,

Previous Faq:

Next Faq: