Linux command line - How to get and set the date and time of system.

Recently, I want to change the system date in linux by using command line. After doing some researches, I get the solutions as stated below:

The date command can be used as follows to display the time and date:

# date
Fri Mar 28 16:01:50 CST 2003

To see UTC/GMT, you can do this:

# date –utc
Fri Mar 28 08:04:32 UTC 2003

The date command also can be used to set the time and date. To set the time manually, do this:

# date -s “16:15:00″
Fri Mar 28 16:15:00 CST 2003

If you also need to adjust the date, and not just the time, you can do it like this:

# date -s “16:55:30 July 7, 1986″
Mon Jul  7 16:55:30 PDT 1986

There is also another way to set the date and time, which is not very pretty:

# date 033121422003.55
Mon Mar 31 21:42:55 PST 2003

The above command does not use the -s option, and the fields are arranged like this:  MMDDhhmmCCYY.ss
where MM = month, DD = day, hh = hour, mm = minute, CCYY = 4 digit year, and ss = seconds.

Please note that setting the clock with the date command must be done as root.

December 23rd, 2008 @ 02:29 PM • Filed under Linux

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.