How To Set or Change Timezone on CentOS 7
When starting up a new server, you'll almost always need to establish the timezone. You may wish to adjust your timezone in certain circumstances.
Many of us forget to set the correct timezone on our servers. Your server's reports and logs will be impacted if you choose an incorrect timezone. As a result, we'll teach you how to configure a timezone in CentOS 7 in this article.
Setting the correct time zone for your CentOS-based VPS is critical for reliably recording timestamps; otherwise, you may wind up reporting an incident or error log with the erroneous date and timestamp.
Aside from logging and reporting, the time specified for crontabs and scheduled processes is also critical. Setting the time zone incorrectly may cause the operations to execute differently than planned. Fortunately, you need to run a few accessible commands to change the timezone in CentOS 7!
Overall, failing to select the correct time zone will not damage your operation, but it will significantly enhance your productivity and eliminate any ambiguity in your logs.
Let's look at how to change the time zone in CentOS 7.
In CentOS 7, how can I check the set timezone?
First and foremost, we must use SSH to connect to our VPS server. Refer to the PuTTY instruction if you're experiencing problems!
The date command, as seen below, may be used to determine your current time zone:
The time will be shown in the following format:
The time now is 14:52:20 UTC on Friday, March 15, 2019.
Alternatively, the timedatectl command may be used. This command can be used to:
- Examine the timestamps and dates.
- Make a date and time change.
- Set the system's timezone and enable automatic clock synchronization with a remote server.
The fundamental command is as follows:
The following is an example of the output:
Local time is 14:54:51 UTC on Friday, March 15, 2019.
Fri, March 15th, 2019 at 14:54:51 UTC
n/a n/a n/a n/a n/a n/
Host (UTC, +0000) is the time zone.
n/a n/a n/a n/a n/a n/
Yes, NTP is synced.
RTC in the local time zone: no DST is in effect: n/a
Local time, universal time, and timezone are all included in this section.
In CentOS 7, how do you list timezones?
You may wish to display all possible timezone settings once you've seen your current timezone. To see all of the timezone possibilities, use the following command:
You'll be given an extensive list with all the timezones listed alphabetically. Using grep patterns, you may further narrow your search. As an example, consider the following:
How can I change the time zone in CentOS 7?
Once you've compiled a list of timezones, you may choose the one that best suits your needs. In CentOS 7, you may use the following commands to change the timezone:
In the command above, you may change the time zone as needed. We may also specify a particular time and date from here. This may be accomplished using the following format:
For example, if you want the time to be Mar-16-2019 and the current time to be 09:20:00, you may type:
After making these changes, use timedatectl to verify the time zone information.
In CentOS 7, how can you set the hardware clock?
The system clock, handled by the Linux kernel, is not the same as the hardware clock. The BIOS clock is another name for this. When the system is turned off, the hardware clock is activated. The hardware clock may be set using Linux commands.
Use the following command to see whether the hardware clock is configured to the local time zone:
This will provide the following result, indicating that the hardware clock does not have a timezone set:
No RTC in the nearby TZ.
Then, using the command below, adjust your hardware clock to the local time zone:
You may use the following commands to undo the changes:
How to Synchronize Clocks on CentOS 7 The Network Time Protocol (NTP) is an internet protocol used to synchronize system clocks on multiple computers. The timedatectl command may be used to automatically sync a system's time zone with a remote server using NTP.
To do so, we must first have NTP installed on the system. Use the following command to begin synchronization with a distant NTP server:
If you wish to undo these modifications, use the command below. Time synchronization will be disabled as a result of this:
Conclusion
We learned how to configure the timezone on CentOS 7 and how to set the system time, date, hardware clock time, and synchronize systems using NTP. Selecting the proper timezone is crucial for accurate logging, automated procedures, and more!
On CentOS 7, changing the timezone is simple. Yes, you may always consult the timedatectl command's documentation pages to learn about more parameters.