{"id":16046,"date":"2019-03-18T11:54:02","date_gmt":"2019-03-18T11:54:02","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=16046"},"modified":"2026-03-10T09:30:40","modified_gmt":"2026-03-10T09:30:40","slug":"how-to-set-the-timezone-in-centos","status":"publish","type":"post","link":"\/ca\/tutorials\/how-to-set-the-timezone-in-centos\/","title":{"rendered":"How to set the timezone in CentOS 7"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>While you are setting up a new server, very often you might have to set the timezone. In certain cases, you might want to change your timezone.<\/p><p>Setting the appropriate timezone on servers is something many of us forget. Setting an inappropriate timezone will impact your server reporting and logs. That&rsquo;s why in this tutorial, we&rsquo;ll show you how to set a timezone in CentOS 7.<\/p><p>Setting the correct time zone for your CentOS based VPS is important for accurately logging timestamps, else you may end up noting a wrong date and timestamp for the incident or error log.<\/p><p>Apart from logging and reporting, another very important factor is the time set for crontabs and automated jobs. Setting an inappropriate time zone may end up running the processes at a different than actually intended time. Luckily if you want to set the timezone in CentOS 7, you&rsquo;ll only need to use a few simple commands!<\/p><p>Overall, not setting the proper time zone won&rsquo;t break your operation, but will definitely improve your workflow and will easily prevent a lack of clarity in your logs.<\/p><p>Let&rsquo;s learn how to set the timezone in CentOS 7.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\"  sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/div><p>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> CentOS Linux 8 has reached it&rsquo;s End of Lifetime (EOL) on 2021-12-31. While CentOS Linux 7 is still supported, it will reach EOL on 2024-06-30. We recommend keeping that in mind when choosing this OS. You can read more about it in their <a href=\"https:\/\/www.centos.org\/centos-linux-eol\/\" target=\"_blank\" rel=\"noopener\">official website<\/a>.\n            <\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-check-the-set-timezone-in-centos-7\">How to Check the Set Timezone in CentOS 7<\/h2><p>First of all, we need to access our virtual private server using SSH. If you&rsquo;re having trouble, reference the <a href=\"\/ca\/tutorials\/how-to-use-putty-ssh\/\">PuTTY tutorial<\/a>!<\/p><p>You can check your current time zone by using the <strong>date<\/strong> command as shown below:<\/p><pre class=\"wp-block-preformatted\">date<\/pre><p>This will output the time in the following format:<\/p><pre class=\"wp-block-preformatted\">Fri Mar 15 14:52:20 UTC 2019<\/pre><p>Alternatively, you can use the&nbsp;<strong>timedatectl<\/strong> command. This command can:<\/p><ul class=\"wp-block-list\">\n<li>Review the dates and timestamps<\/li>\n\n\n\n<li>Change the date and time<\/li>\n\n\n\n<li>Setup a timezone for the system<\/li>\n\n\n\n<li>Enable automatic synchronization of the clock based on a remote server<\/li>\n<\/ul><p>The basic command looks like this:<\/p><pre class=\"wp-block-preformatted\">timedatectl<\/pre><p>The output will be as shown below:<\/p><pre class=\"wp-block-preformatted\">Local time: Fri 2019-03-15 14:54:51 UTC\n&nbsp;Universal time: Fri 2019-03-15 14:54:51 UTC\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RTC time: n\/a\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time zone: Host (UTC, +0000)\n&nbsp;&nbsp;&nbsp;&nbsp;NTP enabled: n\/a\nNTP synchronized: yes\nRTC in local TZ: no\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DST active: n\/a<\/pre><p>This contains information such as local time, universal time, and timezone.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-list-timezones-in-centos-7\">How to List Timezones in CentOS 7<\/h2><p>Once you have viewed your current timezone, you might want to list all the available timezone options. The below command can be used to list all the timezone options:<\/p><pre class=\"wp-block-preformatted\">timedatectl list-timezones<\/pre><p>You&rsquo;ll get a long list showing all the timezones in alphabetical order. You can refine your search by adding filters using <a href=\"\/ca\/tutorials\/grep-command-in-linux-useful-examples\/\">grep<\/a> patterns. One such example is as shown below:<\/p><pre class=\"wp-block-preformatted\">timedatectl list-timezones | grep Pacific<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-set-timezone-in-centos-7\">How to Set Timezone in CentOS 7<\/h2><p>Once you have the list of timezones, you can set the one you prefer. To set the timezone in CentOS 7, you can use:<\/p><pre class=\"wp-block-preformatted\">timedatectl set-timezone America\/Chicago<\/pre><p>You can replace the time zone accordingly in the command above. Over here we can also set a specific time and date. This can be done using the below format:<\/p><pre class=\"wp-block-preformatted\">timedatectl set-time 'YYYY-MM-DD HH:MM:SS'<\/pre><p>For instance, if you want this to be set the time as Mar-16-2019 and the current time as 09:20:00, then you can use:<\/p><pre class=\"wp-block-preformatted\">timedatectl set-time '2019-03-16 09:20:00'<\/pre><p>After making these changes, you can again check the time zone details using <strong>timedatectl<\/strong>.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-set-the-hardware-clock-in-centos-7\">How to Set the Hardware Clock in CentOS 7<\/h2><p>A hardware clock is different from the system clock which is managed by the Linux kernel. This is also referred to as the BIOS clock. The hardware clock is enabled once the system is shut down. Using Linux commands, you can set the hardware clock.<\/p><p>To check if the hardware clock is set to local time zone use the below command:<\/p><pre class=\"wp-block-preformatted\">timedatectl | grep local<\/pre><p>This will give output as shown below, which means the hardware clock does not have a timezone specified:<\/p><pre class=\"wp-block-preformatted\">RTC in local TZ: no<\/pre><p>Next, you can set your hardware clock to local time zone using the below command:<\/p><pre class=\"wp-block-preformatted\">timedatectl set-local-rtc 1<\/pre><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Pro Tip                <\/p>\n            <\/div>\n            <p class=\"protip__content\">If you're seeing the error \"Failed to set local RTC: Failed to set RTC to local\/UTC: Input\/output error\" when trying to run this command, try editing the file \/etc\/adjtime\/ by adjusting the third line. You can read more about this error over at <a href=\"https:\/\/stackoverflow.com\/questions\/43121386\/unable-to-set-the-mode-of-the-realtime-clock-to-utc\" target=\"_blank\" rel=\"noopener\">Stack Overflow<\/a>.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><p>To revert the changes, you can use:<\/p><pre class=\"wp-block-preformatted\">timedatectl set-local-rtc 0<\/pre><h2 class=\"wp-block-heading\" id=\"h-how-to-perform-clock-synchronization-on-centos-7\">How to Perform Clock Synchronization on CentOS 7<\/h2><p>Network Time Protocol (NTP) is an internet protocol which is commonly used to synchronize system clocks on different computers. The timedatectl command can configure a system&rsquo;s time zone to automatically sync with a remote server using NTP.<\/p><p>To enable this, first, we should have NTP installed on the system. If you don&rsquo;t have this installed on your CentOS device yet, you can do so by installing <a href=\"https:\/\/chrony.tuxfamily.org\/\" target=\"_blank\" rel=\"noopener\">Chrony<\/a>:<\/p><pre class=\"wp-block-preformatted\">yum install chrony<\/pre><p>In order to start synchronization with a remote NTP server use the below command:<\/p><pre class=\"wp-block-preformatted\">timedatectl set-ntp true<\/pre><p>In case you want to revert these changes, use the below command. This will disable time synchronization:<\/p><pre class=\"wp-block-preformatted\">timedatectl set-ntp false<\/pre><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ca\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Here we have seen how to set timezone on CentOS 7 as well as how to set system time, date, hardware clock time and synchronize systems using NTP. Setting the right timezone is important for correct logging, automated processes and more!<\/p><p>It&rsquo;s easy to set the timezone on CentOS 7. And yes, to learn about more options, you can always check the manual pages for the timedatectl command.<\/p><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Learn More About CentOS                <\/p>\n            <\/div>\n            <p class=\"protip__content\"><a href=\"\/ca\/tutorials\/change-hostname-on-centos-7\/\">How to Change Hostname on CentOS<\/a><br>\n<a href=\"\/ca\/tutorials\/vps\/how-to-install-lamp-stack-centos7\/\">How to Install LAMP Stack on CentOS<\/a><br>\n<a href=\"\/ca\/tutorials\/how-to-install-ssl-certificate-on-centos-7\/\">How to Install Let's Encrypt SSL on CentOS<\/a><br>\n<a href=\"\/ca\/tutorials\/how-to-disable-selinux-on-centos-7\/\">How to Disable Selinux on CentOS<\/a><\/p>\n                    <\/div>\n        \n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While you are setting up a new server, very often you might have to set the timezone. In certain cases, you might want to change your timezone. Setting the appropriate timezone on servers is something many of us forget. Setting an inappropriate timezone will impact your server reporting and logs. That&rsquo;s why in this tutorial, [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ca\/tutorials\/how-to-set-the-timezone-in-centos\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":110,"featured_media":139832,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Learn How to Set the Timezone in CentOS 7 \u2013 Complete Beginner's Guide","rank_math_description":"Error logs, chrontabs, automated jobs \u2013 all these functions depend on the correct timezone set on CentOS 7. Learn how to set it correctly!","rank_math_focus_keyword":"set timezone centos","footnotes":""},"categories":[1],"tags":[],"class_list":["post-16046","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/what-is-centos","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-set-the-timezone-in-centos","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/what-is-centos","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/what-is-centos","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/what-is-centos","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/what-is-centos","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-set-the-timezone-in-centos","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-set-the-timezone-in-centos","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/16046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/comments?post=16046"}],"version-history":[{"count":11,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/16046\/revisions"}],"predecessor-version":[{"id":138978,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/16046\/revisions\/138978"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media\/139832"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media?parent=16046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/categories?post=16046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/tags?post=16046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}