Debian 设置或者修改时区
<h2 id="debian-设置或者修改时区">Debian 设置或者修改时区</h2><h3 id="太长不看版">太长不看版</h3>
<ul>
<li>基于systemd的高版本Debian系统</li>
</ul>
<pre><code class="language-shell">sudo timedatectl set-timezone Asia/Shanghai
</code></pre>
<ul>
<li>老掉牙的远古Debian系统</li>
</ul>
<pre><code class="language-bash">sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
</code></pre>
<p>在 Debian 上,系统时区在安装过程中设置,如果你设置的系统语言环境为英语,那么选择时区时,是找不到中国的时区的(如果可以,请评论区指教),所以一般是进入系统后修改为中国时区</p>
<h3 id="检查当前时区">检查当前时区</h3>
<p><code>timedatectl</code>是一个命令行工具,它允许你查看并且修改系统时间和日期。现代所有基于systemd的linux系统中都可以使用它,即使你的Debian10是选择的最小化的基本系统安装(我就是),也是可以使用的</p>
<pre><code class="language-shell">timedatectl
</code></pre>
<p>回车后会输入你系统当前的时区信息</p>
<pre><code class="language-shell"> Local time: Sun 2022-06-12 17:35:14 CST
Universal time: Sun 2022-06-12 09:35:14 UTC
RTC time: Sun 2022-06-12 09:35:14
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
</code></pre>
<p>系统时区通过链接文件<code>/etc/localtime</code>配置,该链接指向<code>/usr/share/zoneinfo</code>目录下的一个二进制时区标识文件。另外一个检查时区的方法就是显示这个链接文件指向的实际路径,使用<code>ls</code>命令</p>
<pre><code class="language-shell">ls -l /etc/localtime
</code></pre>
<h3 id="修改时区">修改时区</h3>
<p>使用<code>timedatectl list-timezones</code>命令或者列出<code>/usr/share/zoneinfo</code>目录下的所有文件来查看当前系统支持的时区</p>
<pre><code class="language-shell">timedatectl list-timezones
</code></pre>
<p>找到自己需要的时区后,使用<code>sudo timedatectl set-timezone 你需要修改的时区</code>来修改时区,修改后可以使用<code>timedatectl</code>命令或者<code>date</code>命令查看是否修改成功</p>
<ul>
<li>如果你正在运行一个比较古老的 Debian 版本,并且<code>timedatectl</code>在你的系统上不可用,你可以通过修改时区的链接文件<code>/etc/localtime</code>到<code>/usr/share/zoneinfo</code>目录下的时区文件来修改时区。<code>sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime</code></li>
</ul>
<h3 id="最后编辑时间2023年1月24日125207">最后编辑时间:2023年1月24日12:52:07</h3><br><br>
来源:https://www.cnblogs.com/tothk/p/16368444.html
頁:
[1]