{"id":1699,"date":"2023-03-25T22:56:27","date_gmt":"2023-03-25T14:56:27","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1699"},"modified":"2023-04-23T21:42:12","modified_gmt":"2023-04-23T13:42:12","slug":"setting-time-zone-using-the-timedatectl-command-in-centos","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/setting-time-zone-using-the-timedatectl-command-in-centos\/","title":{"rendered":"CentOS\u4e0b\u4f7f\u7528timedatectl\u547d\u4ee4\u8bbe\u7f6e\u65f6\u95f4\u65f6\u533a"},"content":{"rendered":"<p><code>timedatectl<\/code>\u547d\u4ee4\u5bf9\u4e8e<code>RHEL<\/code>\/<code>CentOS 7<\/code>\u548c\u57fa\u4e8e<code>Fedora 21+<\/code>\u7684\u5206\u5e03\u5f0f\u7cfb\u7edf\u6765\u8bf4\uff0c\u662f\u4e00\u4e2a\u65b0\u5de5\u5177\uff0c\u5b83\u4f5c\u4e3a<code>systemd<\/code>\u7cfb\u7edf\u548c\u670d\u52a1\u7ba1\u7406\u5668\u7684\u4e00\u90e8\u5206\uff0c\u4ee3\u66ff\u65e7\u7684\u4f20\u7edf\u7684\u7528\u5728\u57fa\u4e8eLinux\u5206\u5e03\u5f0f\u7cfb\u7edf\u7684<code>sysvinit<\/code>\u5b88\u62a4\u8fdb\u7a0b\u7684<code>date<\/code>\u547d\u4ee4\u3002<\/p>\n<p><code>timedatectl<\/code>\u547d\u4ee4\u53ef\u4ee5\u67e5\u8be2\u548c\u66f4\u6539\u7cfb\u7edf\u65f6\u949f\u548c\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b64\u547d\u4ee4\u6765\u8bbe\u7f6e\u6216\u66f4\u6539\u5f53\u524d\u7684\u65e5\u671f\uff0c\u65f6\u95f4\u548c\u65f6\u533a\uff0c\u6216\u5b9e\u73b0\u4e0e\u8fdc\u7a0b<code>NTP<\/code>\u670d\u52a1\u5668\u7684\u81ea\u52a8\u7cfb\u7edf\u65f6\u949f\u540c\u6b65\u3002<\/p>\n<p><!-- more --><\/p>\n<p>\u672c\u6587\u8bb2\u89e3\u5982\u4f55\u4f7f\u7528<code>timedatectl<\/code>\u547d\u4ee4\u7684<code>NTP<\/code>\uff0c\u8bbe\u7f6e<code>date<\/code>\u3001<code>time<\/code>\u3001<code>timezone<\/code>\u548c<code>synchronize time<\/code>\u6765\u7ba1\u7406\u65f6\u95f4\u3002<code>timedatectl<\/code>\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9\uff1a<\/p>\n<p>1\uff09\u7ef4\u62a4\u53ca\u65f6\u64cd\u4f5c\u7684\u7cfb\u7edf\u4efb\u52a1\uff0c\u56e0\u4e3a\u5728Linux\u4e2d\u7684\u5927\u591a\u6570\u4efb\u52a1\u90fd\u662f\u7531\u65f6\u95f4\u6765\u63a7\u5236\u7684<br \/>\n2\uff09\u8bb0\u5f55\u4e8b\u4ef6\u548c\u7cfb\u7edf\u4e0a\u5176\u5b83\u4fe1\u606f\u7b49\u7684\u6b63\u786e\u65f6\u95f4<\/p>\n<h2>\u65f6\u533a\u67e5\u770b\u53ca\u8bbe\u7f6e<\/h2>\n<p>\uff081\uff09\u8981\u663e\u793a\u7cfb\u7edf\u7684\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u4e2d\u7684<code>timedatectl status<\/code>\u547d\u4ee4\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl status\nWarning: Ignoring the TZ variable. Reading the system&#039;s time zone setting only.\n\n      Local time: Wed 2020-09-09 05:57:17 UTC\n  Universal time: Wed 2020-09-09 05:57:17 UTC\n        RTC time: Wed 2020-09-09 05:57:17\n       Time zone: UTC (UTC, +0000)\n     NTP enabled: no\nNTP synchronized: no\n RTC in local TZ: no\n      DST active: n\/a<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code>RTC time<\/code>\u5c31\u662f\u786c\u4ef6\u65f6\u949f\u7684\u65f6\u95f4\u3002<\/p>\n<p>\uff082\uff09Linux\u7cfb\u7edf\u4e0a\u7684<code>time<\/code>\u603b\u662f\u901a\u8fc7\u7cfb\u7edf\u4e0a\u7684<code>timezone<\/code>\u8bbe\u7f6e\u7684\uff0c\u8981\u67e5\u770b\u5f53\u524d\u65f6\u533a\uff0c\u6309\u5982\u4e0b\u505a\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl \nOR\n# timedatectl | grep Time<\/code><\/pre>\n<p>\uff083\uff09\u8981\u67e5\u770b\u6240\u6709\u53ef\u7528\u7684\u65f6\u533a\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl list-timezones<\/code><\/pre>\n<p>\uff084\uff09\u8981\u6839\u636e\u5730\u7406\u4f4d\u7f6e\u627e\u5230\u672c\u5730\u7684\u65f6\u533a\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl list-timezones | egrep -o &quot;\u2019Asia\/B.*&quot;\n# timedatectl list-timezones | egrep -o &quot;Europe\/L.*&quot;\n# timedatectl list-timezones | egrep -o &quot;America\/N.*&quot;<\/code><\/pre>\n<p>\uff085\uff09\u8981\u5728Linux\u4e2d\u8bbe\u7f6e\u672c\u5730\u65f6\u533a\uff0c\u4f7f\u7528set-timezone\u5f00\u5173\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-timezone &quot;Asia\/Shanghai&quot;<\/code><\/pre>\n<p>\u63a8\u8350\u4f7f\u7528\u548c\u8bbe\u7f6e\u534f\u8c03\u4e16\u754c\u65f6\uff0c\u5373UTC<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-timezone UTC<\/code><\/pre>\n<p>\u9700\u8981\u8f93\u5165\u6b63\u786e\u547d\u540d\u7684\u65f6\u533a\uff0c\u5426\u8005\u5728\u6539\u53d8\u65f6\u533a\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u9519\u8bef<\/p>\n<h2>\u65e5\u671f\u53ca\u65f6\u95f4\u8bbe\u7f6e<\/h2>\n<p>\uff081\uff09\u8bbe\u7f6eLinux\u4e2d\u7684\u65f6\u95f4\u3002\u53ea\u8bbe\u7f6e\u65f6\u95f4\u7684\u8bdd\uff0c\u53ef\u4ee5\u4f7f\u7528<code>set-time<\/code>\u5f00\u5173\u4ee5\u53ca<code>HH:MM:SS<\/code>\uff08\u5c0f\u65f6\uff0c\u5206\uff0c\u79d2\uff09\u7684\u65f6\u95f4\u683c\u5f0f<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-time 15:58:30<\/code><\/pre>\n<p>\uff082\uff09\u5728Linux\u4e2d\u8bbe\u7f6e\u65e5\u671f\u3002\u53ea\u8bbe\u7f6e\u65e5\u671f\u7684\u8bdd\uff0c\u53ef\u4ee5\u4f7f\u7528<code>set-time<\/code>\u5f00\u5173\u4ee5\u53ca<code>YYYY-MM-DD<\/code>\uff08\u5e74\uff0c\u6708\uff0c\u65e5\uff09\u7684\u65e5\u671f\u683c\u5f0f<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-time 2018-11-20<\/code><\/pre>\n<p>\uff083\uff09\u8bbe\u7f6e\u65e5\u671f\u548c\u65f6\u95f4<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-time &#039;16:10:50 2018-11-20&#039;<\/code><\/pre>\n<h2>\u5982\u4f55\u5728Linux\u4e2d\u67e5\u627e\u548c\u8bbe\u7f6e\u786c\u4ef6\u65f6\u949f<\/h2>\n<p>\u8981\u8bbe\u7f6e\u786c\u4ef6\u65f6\u949f\u4ee5\u534f\u8c03\u4e16\u754c\u65f6UTC\uff0c\u53ef\u4ee5\u4f7f\u7528<code>set-local-rtc boolean-value<\/code>\u9009\u9879<\/p>\n<p>\u9996\u5148\u786e\u5b9a\u786c\u4ef6\u65f6\u949f\u662f\u5426\u8bbe\u7f6e\u4e3a\u672c\u5730\u65f6\u533a\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl | grep local<\/code><\/pre>\n<p>\u5c06\u786c\u4ef6\u65f6\u949f\u8bbe\u7f6e\u4e3a\u672c\u5730\u65f6\u533a\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-local-rtc 1<\/code><\/pre>\n<p>\u5c06\u786c\u4ef6\u65f6\u949f\u8bbe\u7f6e\u4e3a\u534f\u8c03\u4e16\u754c\u65f6\uff08UTC\uff09\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-local-rtc 0<\/code><\/pre>\n<h2>\u5c06Linux\u7cfb\u7edf\u65f6\u949f\u540c\u6b65\u5230\u8fdc\u7a0bNTP\u670d\u52a1\u5668<\/h2>\n<p>NTP\u5373<code>Network Time Protocol<\/code>\uff08\u7f51\u7edc\u65f6\u95f4\u534f\u8bae\uff09\uff0c\u662f\u4e00\u4e2a\u4e92\u8054\u7f51\u534f\u8bae\uff0c\u7528\u4e8e\u540c\u6b65\u8ba1\u7b97\u673a\u4e4b\u95f4\u7684\u7cfb\u7edf\u65f6\u949f\u3002<code>timedatectl<\/code>\u5b9e\u7528\u7a0b\u5e8f\u53ef\u4ee5\u81ea\u52a8\u540c\u6b65Linux\u7cfb\u7edf\u65f6\u949f\u5230\u4f7f\u7528NTP\u7684\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/p>\n<p>\u6ce8\u610f\uff0c\u5fc5\u987b\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5NTP\u4ee5\u5b9e\u73b0\u4e0eNTP\u670d\u52a1\u5668\u7684\u81ea\u52a8\u65f6\u95f4\u540c\u6b65\u3002<\/p>\n<p>\u8981\u5f00\u59cb\u81ea\u52a8\u65f6\u95f4\u540c\u6b65\u5230\u8fdc\u7a0bNTP\u670d\u52a1\u5668\uff0c\u5728\u7ec8\u7aef\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-ntp true<\/code><\/pre>\n<p>\u8981\u7981\u7528NTP\u65f6\u95f4\u540c\u6b65\uff0c\u5728\u7ec8\u7aef\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\"># timedatectl set-ntp false<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>timedatectl\u547d\u4ee4\u5bf9\u4e8eRHEL\/CentOS 7\u548c\u57fa\u4e8eFedora 21+\u7684\u5206\u5e03\u5f0f\u7cfb\u7edf\u6765\u8bf4\uff0c\u662f\u4e00\u4e2a\u65b0\u5de5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[331],"tags":[424],"class_list":["post-1699","post","type-post","status-publish","format-standard","hentry","category-linux","tag-424"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1699"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1699\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}