In this tutorial we are going to show you how to set up the time zone on a Linux VPS running CentOS 7 as an operating system.
To set up the time and date on CentOS 7 we are going to use the timedatectl command. It is an utility which is distributed as part of the systemd system and service manager. The timedatectl command has the following features:
– Review the current date and time
– Change the date and time
– Set up the system time zone
– Enable an automatic synchronization of the system clock with a remote server
First of all, connect to your CentOS VPS via SSH. It is always a good practice to update all your system software to the latest version available. You can do that using the following command:
# yum update
Once the update is completed, review the configuration of the system clock by using the timedatectl command:
# timedatectl Local time: Fri 2016-06-02 04:21:01 EDT Universal time: Fri 2016-06-02 08:21:01 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-03-13 01:59:59 EST Sun 2016-03-13 03:00:00 EDT Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2016-11-06 01:59:59 EDT Sun 2016-11-06 01:00:00 EST
The output of the command should be similar to the one above. As you can see, many information are provided in the output of the timedatectl command like local time, universal time, current time zone, whether NTP is enabled or not, last DST change, next DST change etc.
The next thing you might like to do is to set up the time zone. To list the time zones available you can use the following command:
# timedatectl list-timezones
The output is large and you can use grep to filter the results. For example, if you like to list the American time zones, you can use the command below:
# timedatectl list-timezones | grep America America/Adak America/Anchorage America/Anguilla America/Antigua America/Araguaina America/Argentina/Buenos_Aires America/Argentina/Catamarca America/Argentina/Cordoba America/Argentina/Jujuy America/Argentina/La_Rioja America/Argentina/Mendoza America/Argentina/Rio_Gallegos America/Argentina/Salta America/Argentina/San_Juan America/Argentina/San_Luis America/Argentina/Tucuman America/Argentina/Ushuaia America/Aruba America/Asuncion America/Atikokan America/Bahia America/Bahia_Banderas America/Barbados ...
To set up the time zone use the following command:
# timedatectl set-timezone America/Chicago
Here, you can replace America/Chicago with the name of the time zone you like to set. Use the timedatectl command again to review the changes.
To set a specific time and date you can use the following syntax:
# timedatectl set-time 'YYYY-MM-DD HH:MM:SS'
For example, to set up the current date to May-06-2016 and the current time to 21:55:00, use the command below:
# timedatectl set-time '2016-06-02 21:55:00'
More information on how to use the timedatectl command you can find by 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=[USER@]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
Of course you don’t have to do any of this if you use one of our Linux VPS hosting services, in which case you can simply ask our expert Linux admins to set up the time zone on your system for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.