How to Set CentOS / RHEL Date and Time

This is not pleasant if the Linux server time and date is wrong, and you need to set it to new values from the shell prompt. In this Article, we Show you How to Set CentOS 7, 6, older Date/Time and Timezone with Command Prompt.

How to Set Date and Time on CentOS 6 and older

The best solution is to select the Timezone in the first step and then set the date and time.

1. backup the current timezone

cp /etc/localtime /etc/localtime-ori

2. Copy new Timezone to current, In the /user/share/zoneinfo folder, you can find your desired timezone and copy to the current timezone.

cd /usr/share/zoneinfo/America/
cp New_York /etc/localtime

3. Manually Set Date and Time

# date MMDDhhmmYYYY

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 120911052018

4. Set Date and Time with ntp

yum install ntp ntpdate
chkconfig ntpd on
service ntpd start
ntpdate pool.ntp.org

Tip: The above method is also working in CentOS 7, but there is a newer Method in CentOS 7 which we will explain below.

How to Set Date and Time on CentOS 7

1. install ntp for sync Time and Date

yum install ntp ntpdate
systemctl start ntpd
systemctl enable ntpd

2. Set Current Timezone

timedatectl list-timezones | grep -i america
timedatectl set-timezone “America/New_York”

Verify it:

timedatectl

3. Set Manually Time and Date

timedatectl set-time YYYY-MM-DD HH:MM:SS
timedatectl set-time '2018-11-23 08:10:40'

timedatectl set-time YYYY-MM-DD
timedatectl set-time '2018-12-01'

timedatectl set-time HH:MM:SS 
timedatectl set-time '10:42:43'

4. synchronizing the system clock

timedatectl set-ntp yes

Verify it:

timedatectl status