Hack 7. Set System Date and Time

by Ramesh

To change the system date use:

# date {mmddhhmiyyyy.ss}

o mm – Month
o dd – Date
o hh – 24 hour format
o mi – Minutes
o yyyy – Year
o ss – seconds

For example, to set system date to Jan 31st 2009, 10:19 p.m, 53 seconds

# date 013122192009.53

You can also change system date using set argument as shown below.

# date 013122192009.53

# date +%Y%m%d -s "20090131"

# date -s "01/31/2009 22:19:53" 

# date -s "31 JAN 2009 22:19:53"

# date set="31 JAN 2009 22:19:53"

To set the time only:

# date +%T -s "22:19:53"

# date +%T%p -s "10:19:53PM"

{ 2 comments… read them below or add one }

1 Ravi R November 29, 2012 at 5:13 am

Hi,

Most times you want to set the system date to the current date. I find rdate or ntpdate much more useful for this if you are connected to the internet and they are much more accurate (you give a time server to get the time from).

-Ravi

2 joe ching November 30, 2012 at 7:38 pm

“For example, to set system date to Jan 31st 2008,” it should be “…2009″ to match the following example. :)

Leave a Comment

Previous post:

Next post: