Wednesday, February 2, 2011

Change date on Linux machine

Not once we need to adjust time on a Linux server (when NTP server is not reachable for any reason).

The date command can be used to set the time and date. 

To set the time manually, execute as root:
# date -s "15:13:00"
  Wed Feb 2 15:13:00 CST 2011

If you need to adjust the full date, and not just the time:

# date -s "15:13:30 Feb 2, 2011"
Wed Feb 2 15:13:30 PDT 2011

There is also another way to set the date and time (less elegant):

# date 033121422011.55
Mon Mar 31 21:42:55 PST 2011

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

No comments: