You may need to change or set the Date and Time in Linux from the console (also know as the command prompt by Windows users). The best option is to sync with an NTP but this short guide will show you how to set the Date and Time in Linux manually. This guide uses CentOS Linux but it should apply to any Linux distribution.

Set the Date and Time in Linux

As root use the date command to set the date and time in CentOS:

$ date MMDDhhmmYYYY

Replace MMDDhhmmYYYY with the appropriate values. The values are:

MM – Two digit month number
DD – Two digit date
hh – Two digit 24 hour system hour
mm – Two digit minute
YYYY – Four digit year code

Example:

$ date 061211232010

This will set the date to: Sat Jun 12 11:23:00 EDT 2010

Setting Only the Time in Linux

$ date --set hh:mm

hh – Two digit 24 hour system hour
mm – Two digit minute

Examples:

$ date --set 06:00 ;sets the time to 6:00AM
$ date --set 18:00 ;sets the time to 6:00PM

Setting Only the Date in Linux

$ date +%Y%m%d -s "YYYYMMDD"

Examples:

$ date +%Y%m%d -s "20100612"

This will set the date to June 12th, 2010.