如何在 Rocky Linux 9 上更改时区

Linux命令 Edge插件网 2年前 (2023-03-04) 1354次浏览 已收录 0个评论

系统的时区是系统所在的地理区域。它确定本地时间,用于在系统上显示日期和时间。默认情况下,时区是在安装操作系统期间设置的。但是,如果移动到新位置或在安装过程中时区设置不正确,则可能需要更改时区如何在 Rocky Linux 9 上更改时区

在 Rocky Linux 9 上更改时区

第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:

<span class="pln">sudo dnf check</span><span class="pun">-</span><span class="pln">update
sudo dnf install dnf</span><span class="pun">-</span><span class="pln">utils</span>

第 2 步。检查您当前的时区。

要检查当前时区,请显示使用以下命令的日期和时间:timedatectl

<span class="pln">timedatectl</span>

输出:

<span class="pun">[</span><span class="pln">root@idroot</span><span class="pun">.</span><span class="pln">us </span><span class="pun">~]#</span><span class="pln"> timedatectl
               </span><span class="typ">Local</span><span class="pln"> time</span><span class="pun">:</span> <span class="typ">Mon</span> <span class="lit">2022</span><span class="pun">-</span><span class="lit">12</span><span class="pun">-</span><span class="lit">17</span> <span class="lit">23</span><span class="pun">:</span><span class="lit">46</span><span class="pun">:</span><span class="lit">36</span><span class="pln"> EDT
           </span><span class="typ">Universal</span><span class="pln"> time</span><span class="pun">:</span> <span class="typ">Tue</span> <span class="lit">2022</span><span class="pun">-</span><span class="lit">12</span><span class="pun">-</span><span class="lit">18</span> <span class="lit">03</span><span class="pun">:</span><span class="lit">46</span><span class="pun">:</span><span class="lit">36</span><span class="pln"> UTC
                 RTC time</span><span class="pun">:</span> <span class="typ">Tue</span> <span class="lit">2022</span><span class="pun">-</span><span class="lit">12</span><span class="pun">-</span><span class="lit">18</span> <span class="lit">03</span><span class="pun">:</span><span class="lit">46</span><span class="pun">:</span><span class="lit">36</span>
                <span class="typ">Time</span><span class="pln"> zone</span><span class="pun">:</span> <span class="typ">America</span><span class="pun">/</span><span class="typ">New_York</span> <span class="pun">(</span><span class="pln">EDT</span><span class="pun">,</span> <span class="pun">-</span><span class="lit">0400</span><span class="pun">)</span>
<span class="typ">System</span><span class="pln"> clock </span><span class="kwd">synchronized</span><span class="pun">:</span><span class="pln"> yes
              NTP service</span><span class="pun">:</span><span class="pln"> active
          RTC </span><span class="kwd">in</span> <span class="kwd">local</span><span class="pln"> TZ</span><span class="pun">:</span> <span class="kwd">no</span>

因此,检查时区的另一个选项是使用以下命令检查路径符号链接:ls

<span class="pln">ls </span><span class="pun">-</span><span class="pln">l </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">localtime</span>

输出:

<span class="pun">[</span><span class="pln">root@idroot</span><span class="pun">.</span><span class="pln">us </span><span class="pun">~]#</span><span class="pln"> ls </span><span class="pun">-</span><span class="pln">l </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">localtime
lrwxrwxrwx</span><span class="pun">.</span> <span class="lit">1</span><span class="pln"> root root </span><span class="lit">18</span> <span class="typ">Dec</span> <span class="lit">17</span> <span class="lit">03</span><span class="pun">:</span><span class="lit">46</span> <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">localtime </span><span class="pun">-></span> <span class="pun">../</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">share</span><span class="pun">/</span><span class="pln">zoneinfo</span><span class="pun">/</span><span class="typ">America</span><span class="pun">/</span><span class="typ">New_York</span>

第 3 步。在 Rocky Linux 9更改时区

更改时区之前,您必须找出要使用的时区的长名称。时区命名约定通常使用“区域/城市”格式。使用命令列出时区:timedatectl

<span class="pln">timedatectl list</span><span class="pun">-</span><span class="pln">timezones</span>

输出:

<span class="pun">[</span><span class="pln">root@idroot</span><span class="pun">.</span><span class="pln">us </span><span class="pun">~]#</span><span class="pln"> timedatectl list</span><span class="pun">-</span><span class="pln">timezones
</span><span class="typ">Africa</span><span class="pun">/</span><span class="typ">Abidjan</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Accra</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Addis_Ababa</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Algiers</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Asmara</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Bamako</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Bangui</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Banjul</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Brazzaville</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Bujumbura</span>
<span class="typ">Africa</span><span class="pun">/</span><span class="typ">Cairo</span>

滚动列表并找到要设置的时区。例如,要将时区设置为东部标准时间,您会在列表中找到“”。通过输入以下命令设置时区,将“TIMEZONE”替换为要设置的时区:America/New_York

<span class="pln">timedatectl </span><span class="kwd">set</span><span class="pun">-</span><span class="pln">timezone TIMEZONE</span>

例如,要将时区设置为东部标准时间,应输入以下命令:

<span class="pln">timedatectl </span><span class="kwd">set</span><span class="pun">-</span><span class="pln">timezone </span><span class="typ">America</span><span class="pun">/</span><span class="typ">New_York</span>

要验证时区是否已正确设置,请输入以下命令:

<span class="pln">timedatectl</span>

输出:

<span class="pun">[</span><span class="pln">root@server </span><span class="pun">~]#</span><span class="pln"> timedatectl
               </span><span class="typ">Local</span><span class="pln"> time</span><span class="pun">:</span> <span class="typ">Tue</span> <span class="lit">2022</span><span class="pun">-</span><span class="lit">12</span><span class="pun">-</span><span class="lit">17</span> <span class="lit">23</span><span class="pun">:</span><span class="lit">42</span><span class="pun">:</span><span class="lit">50</span><span class="pln"> GMT
           </span><span class="typ">Universal</span><span class="pln"> time</span><span class="pun">:</span> <span class="typ">Tue</span> <span class="lit">2022</span><span class="pun">-</span><span class="lit">12</span><span class="pun">-</span><span class="lit">18</span> <span class="lit">03</span><span class="pun">:</span><span class="lit">46</span><span class="pun">:</span><span class="lit">53</span><span class="pln"> UTC
                 RTC time</span><span class="pun">:</span> <span class="typ">Tue</span> <span class="lit">2022</span><span class="pun">-</span><span class="lit">12</span><span class="pun">-</span><span class="lit">18</span> <span class="lit">03</span><span class="pun">:</span><span class="lit">46</span><span class="pun">:</span><span class="lit">53</span>
                <span class="typ">Time</span><span class="pln"> zone</span><span class="pun">:</span> <span class="typ">America</span><span class="pun">/</span><span class="typ">New_York</span> <span class="pun">(</span><span class="pln">GMT</span><span class="pun">,</span> <span class="pun">+</span><span class="lit">0000</span><span class="pun">)</span>
<span class="typ">System</span><span class="pln"> clock </span><span class="kwd">synchronized</span><span class="pun">:</span><span class="pln"> yes
              NTP service</span><span class="pun">:</span><span class="pln"> active
          RTC </span><span class="kwd">in</span> <span class="kwd">local</span><span class="pln"> TZ</span><span class="pun">:</span> <span class="kwd">no</span>

感谢您使用本教程更改 Rocky Linux 9 系统上的时区。如需其他帮助或有用信息,我们建议您查看 Rocky Linux 官方网站。


Edge插件网 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何在 Rocky Linux 9 上更改时区
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址