≡ Menu

Linux Set Date and Time From a Command Prompt

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:
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 136 comments… add one }

  • Johan Dalevi April 8, 2007, 8:51 pm

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

    • PRADEEP December 20, 2010, 3:19 am

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

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

      I want to set the date and time on my phone

  • mani December 12, 2007, 6:57 am

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

  • raju January 10, 2008, 7:25 am

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

  • kiran March 8, 2008, 4:26 am

    It Work’s Thanks a Lot,

    Kiran.

    • varun September 8, 2010, 12:26 pm

      thank

  • djeikyb May 21, 2008, 12:18 am

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

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

  • Mohit Guleria June 27, 2008, 5:08 pm

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

    • Maurice March 6, 2013, 6:38 am

      This is actually an important one!! Many thanks!

    • bryan April 23, 2014, 2:05 pm

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

  • Paolo July 24, 2008, 12:16 pm

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

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

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

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

  • Abdussami October 26, 2008, 11:35 am

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

    May allah bless you…

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

  • D November 2, 2008, 10:09 am

    Thanks

  • pramod November 7, 2008, 4:11 am

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

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

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

    thanks !
    very nice article, super easy :)

  • Venu Reddy December 18, 2008, 6:35 am

    Thanks brother,
    It has worked. Great work…!

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

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

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

    • Aman September 2, 2011, 5:58 am

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

    • zia March 6, 2012, 3:02 am

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

  • Adnan February 17, 2009, 9:01 am

    Thanx alot.. working properly

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

  • C Chavez March 3, 2009, 9:41 pm

    SIDE NOTE RE: SETTING HWCLOCK

    format should be:

    # hwclock –systohc

    (note double -)

    CHeers!

  • George March 18, 2009, 5:57 am

    Thanks alot

    THis has worked like yesterday

    Keep up the good work.

    Regards,

    George Ndung’u
    IT & Logistics Manager
    LSHS

  • Ajay Shaldiwal March 20, 2009, 6:30 am

    Dear Sir,

    Thanks a Lot.

    Ajay

  • Mister D May 5, 2009, 9:17 am

    Thanks!!!

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

  • Zahid May 14, 2009, 12:26 pm

    Nice

  • cat June 1, 2009, 12:12 pm

    Thank you so much, it works.

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

  • Alan July 25, 2009, 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!)

  • herMz August 10, 2009, 9:33 am

    this is awesome.. thnks a lot..

  • Srini August 18, 2009, 2:01 pm

    Thanks…:)

  • FAHIM August 28, 2009, 3:48 pm

    Thanks its works….!!!

  • Dattatray Naik September 5, 2009, 7:42 am

    Thanks It Works.

  • vignesh September 6, 2009, 7:03 am

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

  • Murugesh September 8, 2009, 5:33 pm

    info date Examples

  • thomas September 16, 2009, 11:12 am

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

  • Kent September 25, 2009, 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!

  • seth October 1, 2009, 2:18 pm

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

  • bharanitharan October 5, 2009, 11:16 pm

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

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

    Dear sir,
    Many Thanks for the help
    Thanks

  • Mario Chamorro November 4, 2009, 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

    • LINUXKIDA January 9, 2015, 1:47 pm

      is there any command to find date after x days in future

  • Jaxon November 9, 2009, 8:35 am

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

  • sin December 9, 2009, 6:31 pm

    thanks it worked in first time… Really Thanks

  • Sana December 22, 2009, 4:43 am

    Thanks a lot for your help

  • nenopera January 18, 2010, 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

  • sumer February 8, 2010, 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…………

  • shabbirali March 3, 2010, 8:07 am

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

  • sumer March 3, 2010, 10:21 am

    thanks guys….lov u ……..

  • ratish singh March 15, 2010, 1:41 pm

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

  • vishal April 9, 2010, 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

    • sunraj June 9, 2010, 1:28 pm

      i like your commands. i am realy very impress

  • Indika April 23, 2010, 5:09 pm

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

  • the birdie April 29, 2010, 11:20 am

    Thanks for passing on your knowledge.

  • luciano May 13, 2010, 3:22 pm

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

  • gayan June 11, 2010, 3:45 am

    thinks bro,

  • Vikas YAdav June 26, 2010, 8:36 am

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

  • praV July 9, 2010, 4:47 pm

    THANKS

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

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

  • kiran October 25, 2010, 9:19 am

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

    regards,
    kiran ugale.

  • vijay November 9, 2010, 4:28 am

    Thanks a lot guys.. Everything worked.

  • William Simbota November 11, 2010, 12:46 pm

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

  • Naresh Babu December 21, 2010, 12:26 pm

    Information about date was very much helped me
    Thanks

  • seachen January 13, 2011, 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

  • iskandar January 27, 2011, 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?

  • iskandar January 27, 2011, 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

  • micxz March 18, 2011, 3:34 pm

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

  • ankit maini March 22, 2011, 1:13 pm

    thanx :)

  • dani March 25, 2011, 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

  • Mohit G April 11, 2011, 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

  • mz May 24, 2011, 9:41 am

    it worked fine.
    MZ

  • Jaat June 25, 2011, 11:07 am

    How to change duplex setting of lan card in Rhel5

    • Brent November 30, 2012, 10:54 pm

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

  • sasi July 30, 2011, 11:27 am

    thankz

  • Erik Martis August 16, 2011, 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

  • prince f November 14, 2011, 6:37 pm

    thank you!

  • Soni Peterson December 23, 2011, 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.

  • surendra February 6, 2012, 11:00 am

    Thanks

  • sam March 6, 2012, 10:32 am

    not a big deal , just type :

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

    That’s IT :)

  • prabhat March 27, 2012, 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……..

    • sam March 28, 2012, 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 :)

      • prabhat singh March 30, 2012, 2:06 pm

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

        • sam April 3, 2012, 9:28 am

          nothing ;

          just to make sure run :
          #date

          and see the date ;

  • sunay September 12, 2012, 8:21 am

    its easy to change date or time

  • Rao September 14, 2012, 2:22 pm

    Helped a lot…Thanks…

  • Ahamed Bauani October 11, 2012, 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 :(

  • Sam October 12, 2012, 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

  • Sam October 17, 2012, 8:01 pm

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

  • hapoint from bpoint October 31, 2012, 12:58 pm

    Thanks :)

  • dipesh March 15, 2013, 3:47 pm

    This is all awesome guys… many thanks

  • Ricky1990 April 8, 2013, 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 !

  • Milton May 11, 2013, 7:33 am

    Very helpful article.

  • yusuf October 19, 2013, 11:48 am

    HI,

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

  • PRAVEEN November 19, 2013, 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]

  • Sam November 19, 2013, 6:00 am

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

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

  • sal November 22, 2013, 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?

  • Sam November 24, 2013, 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

  • sal November 25, 2013, 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.

  • Sam November 26, 2013, 8:46 am

    Dear ,

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

    # uname -a

    Thanks

  • taufeeq January 12, 2014, 6:04 am

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

  • Sam January 13, 2014, 1:51 pm

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

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

    • taufeeq January 18, 2014, 5:36 am

      any trick to change?

  • sam January 18, 2014, 7:43 pm

    please send me the output of the below command :

    # uname -a

  • taufeeq January 19, 2014, 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 ~]$

    • Nix Craft January 19, 2014, 10:57 am

      You need to run date as root user:

      sudo date --set="4 JAN 2014 13:25:00"
      • taufeeq January 19, 2014, 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:

        • Nix Craft January 19, 2014, 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.

          • taufeeq January 20, 2014, 1:28 pm

            ok got it thx for help

  • sam January 19, 2014, 9:43 am

    Mr. Taufeeq

    here is my Skype ID :

    mos3535

    regards
    mosleh

  • taufeeq January 19, 2014, 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 ~]$

  • sam January 19, 2014, 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

    • taufeeq January 20, 2014, 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

  • sam January 20, 2014, 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

  • Maurice March 6, 2014, 9:17 pm

    It even worked on the OLPC XO1

  • evhol June 3, 2014, 6:41 am

    thanks

  • Ajit June 6, 2014, 5:47 pm

    Thanks a lot.

  • kishan June 17, 2014, 5:39 am

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

  • Matt July 1, 2014, 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?

  • sam July 2, 2014, 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”

  • Fela August 12, 2014, 1:09 pm

    thanks for sharing

  • Imad September 6, 2014, 9:48 am

    Really helped me.
    thanks for sharing..

  • Narayana Reddy September 19, 2014, 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 .

    • Fela October 9, 2014, 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

  • vsj October 8, 2014, 2:01 am

    it works thanks

  • Gunasekar October 29, 2014, 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

  • tewst November 24, 2014, 9:04 am

    what about service ntpd? need to stop before time change?

Leave a Comment