In this tutorial, we are going to show you how to set up a timezone on a Linux VPS running CentOS 7 as the operating system.
In order to set the time and date on CentOS 7 we will use the command timedatectl… It is a utility that is distributed as part of the Systemd system and service manager. The timedatectl command has the following features:
- Overview of the current date and time
- Change date and time
- Setting the system time zone
- Enabling automatic synchronization of the system clock with a remote server
First of all, let’s connect to the CentOS VPS via SSH. It is always good practice to update all system software to the latest version available. You can do this with the following command:
# yum update
After the update is complete, check the system clock settings using the timedatectl command:
# timedatectl Local time: Fri 2016-07-04 03:21:11 EDT Universal time: Fri 2016-07-04 07:21:11 UTC RTC time: n/a Time zone: America/New_York (EDT, -0400) NTP enabled: n/a NTP synchronized: no RTC in local TZ: no DST active: yes Last DST change: DST began at Sun 2016-01-11 02:59:29 EST Sun 2016-01-11 04:00:10 EDT Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2016-09-04 02:59:29 EDT Sun 2016-09-04 02:00:10 EST
The command output should be similar to the one above. As you can see, a lot of information is presented in the output of the timedatectl command like local time, UTC, current timezone, whether NTP is enabled or not, last DST change, next DST change, etc.
The next thing you could do is set your timezone. To get a list of available time zones you can use the following command:
# timedatectl list-timezones
The output can be great and you can use Grep to filter the results. For example, if you want to list American time zones, you can use the following command:
# timedatectl list-timezones | grep Europe Europe/Kaliningrad ... Europe/Moscow ... Europe/Samara ... Europe/Uzhgorod ... Europe/Volgograd ...
Use the following command to set the time zone:
# timedatectl set-timezone Europe/Moscow
Here you can replace Europe / Moscow with the name of the time zone you want to set. Use the timedatectl command again to view the changes.
To set a specific date and time, you can use the following syntax:
# timedatectl set-time 'YYYY-MM-DD HH:MM:SS'
For example, to set the current date 09-09-2016 and the current time 16:20:00, use the command below:
# timedatectl set-time '2016-09-09 16:20:00'
You can find more details on how to use the timedatectl command using the -help flag:
# timedatectl --help timedatectl [OPTIONS...] COMMAND ... Query or change system time and date settings. -h --help Show this help message --version Show package version --no-pager Do not pipe output into a pager --no-ask-password Do not prompt for password -H --host=[[email protected]]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --adjust-system-clock Adjust system clock when changing local RTC mode Commands: status Show current time settings set-time TIME Set system time set-timezone ZONE Set system time zone list-timezones Show known time zones set-local-rtc BOOL Control whether RTC is in local time set-ntp BOOL Control whether NTP is enabled
PS … If you liked this post, please share it with your friends on social networks using the buttons on the left side of the post, or just leave a comment below. Thank you in advance.