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.
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)
- 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"
See also:
- You can also set new timzone using this mini-howto.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 98 comments… read them below or add one }
Found out i had to set the date like this:
# date -s 2007.04.08-22:46+0000
date -s “2 OCT 2006 18:00:00″
How can I set the proxy setting from the command prompt (bash shell)?
Just This code is ultimate.It is simple and worth full.Thank you very much providing help to people.
It Work’s Thanks a Lot,
Kiran.
thank
mani– run:
export http_proxy=’http://10.10.1.2:3128′
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.
Do check and sync hardware clock with:
# hwclock –show
# hwclock –systohc
This is actually an important one!! Many thanks!
This configuration string is exactly what i’m searching for. thanks.
i had to set the date by using {date -s “wed jul 30 19:41:00 BST 2008″} while at the root.
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
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 formatJust amazing command… & help.. gr88 work.. keep it up.
May allah bless you…
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.
Thanks
this is gr8
I synced HW clk with sysstem clock also.
But after reboot the time is again changed
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!
thanks !
very nice article, super easy :)
Thanks brother,
It has worked. Great work…!
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?
Anyone has ideas how to set Dates 1 day or 2 dates ago. What about setting it +2 hours in advance etc ?
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. . .
date –set=”2 sep 2011 11:27:20″
date -s ”2 OCT 2006 18:00:00″ Thanks it worked nicely oh! thanks
Thanx alot.. working properly
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.
SIDE NOTE RE: SETTING HWCLOCK
format should be:
# hwclock –systohc
(note double -)
CHeers!
Thanks alot
THis has worked like yesterday
Keep up the good work.
Regards,
George Ndung’u
IT & Logistics Manager
LSHS
Dear Sir,
Thanks a Lot.
Ajay
Thanks!!!
One more thank you for your simple explanation and great example. I couldn’t figure out the format from reading the date man page.
Nice
Thank you so much, it works.
Thank you! This information was very helpful.
Some of the examples you have presented here would be hard to derive from the
dateman page.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!)
this is awesome.. thnks a lot..
Thanks…:)
Thanks its works….!!!
Thanks It Works.
Thanks for giving the command.. It’s very helpful for me.
info date Examples
I am a layman in linux, but this sure helped me change my server time remotely.thankyou.
Thanks C Chavez. I had a real time trying to get the hwclock to stop resetting. One line and BAM! Thanks again!
THIS COMMAND DOESN’T WORK FOR OPEN BSD TO CHANGE THE DATE AND TIME
Thanks Man :) it have worked for me ;-)
Dear sir,
Many Thanks for the help
Thanks
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
It works, I have to check any time changing after restart the PC
thanks it worked in first time… Really Thanks
Thanks a lot for your help
$ 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
`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…………
Date command is sweet and simple… :)
Man page is man!!!
thanks guys….lov u ……..
How can i change my system date format on linux os?
satish,
follow the steps
1.check date with date command
2.set date with date -s command
3.hwclock –systohc
4.hwclock –show
Vishal
i like your commands. i am realy very impress
Hi this is really helpful guys….. thanks alot.
Thanks for passing on your knowledge.
# date set=”2 OCT 2006 18:00:00″ wrong!!!!
# date –set=”2 OCT 2006 18:00:00″
thinks bro,
It was amazing……!!!!!!!!!
THANKS
Thank yo very much for sharing your knowledge
It’ really works fine
So… bye
Thank you very much for giving me suggestion it is very usefull for me.
regards,
kiran ugale.
Thanks a lot guys.. Everything worked.
I really appreciate. I think I will learn Linux at a fast pace with your assistance.
Information about date was very much helped me
Thanks
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
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?
now i understand how tht comman
tq friend..
now my fedora time is ok
the time is ok not change anymore..
Tq
not a big deal but small typo:
# 30: Second (ss)
should read 13 or in the example it should be :30
thanx :)
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
it worked fine.
MZ
How to change duplex setting of lan card in Rhel5
On the same subject, how do I make non-dairy chocolate chip cookies?
thankz
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
thank you!
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.
Thanks
not a big deal , just type :
#date 030613252012
03=March
06=Day
13=Hour
25=Min
2012=Year
That’s IT :)
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……..
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 :)
after running this command , do i have to run any other command also?
nothing ;
just to make sure run :
#date
and see the date ;
its easy to change date or time
Helped a lot…Thanks…
Thanks a lot for your help. But problem is there is no way to change the date if it is a VPS server :(
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
Could you please tel me what distribution of linux that you are using ?
Thanks :)
This is all awesome guys… many thanks
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 !
Very helpful article.