本文转载至:http://mathslinux.org/?p=637
Linux 系统(我特指发行版, 没说内核) 下大部分软件的风格就是不会仔细去考虑向后 的兼容性, 比如你上个版本能用这种程序配置, 没准到了下一个版本, 该程序已经不见了. 比如 sysvinit 这种东西.
设置时区同样, 在 CentOS 7 中, 引入了一个叫 timedatectl 的设置设置程序.
用法很简单:
<span style="color: rgb(102, 102, 102);"><em># timedatectl # 查看系统时间方面的各种状态</em></span> Local time: 四 2014-12-25 10:52:10 CST Universal time: 四 2014-12-25 02:52:10 UTC RTC time: 四 2014-12-25 02:52:10 Timezone: Asia<span style="font-weight: bold;">/</span>Shanghai <span style="color: rgb(122, 8, 116);"><strong>(</strong></span>CST, +0800<span style="color: rgb(122, 8, 116);"><strong>)</strong></span> NTP enabled: <span style="color: rgb(194, 12, 185);"><strong>yes</strong></span> NTP synchronized: <span style="color: rgb(194, 12, 185);"><strong>yes</strong></span> RTC <span style="font-weight: bold;">in</span> <span style="color: rgb(122, 8, 116);"><strong>local</strong></span> TZ: no DST active: n<span style="font-weight: bold;">/</span>a |
<span style="color: rgb(102, 102, 102);"># </span>timedatectl list-timezones <span style="color: rgb(102, 102, 102);"><em># 列出所有时区</em></span> |
<span style="color: rgb(102, 102, 102);"># </span>timedatectl set-local-rtc 1 <span style="color: rgb(102, 102, 102);"><em># 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间</em></span> |
<span style="color: rgb(102, 102, 102);"># </span>timedatectl set-timezone Asia<span style="font-weight: bold;">/</span>Shanghai <span style="color: rgb(102, 102, 102);"><em># 设置系统时区为上海</em></span> |
其实不考虑各个发行版的差异化, 从更底层出发的话, 修改时间时区比想象中要简单:
<span style="color: rgb(102, 102, 102);"># </span><span style="color: rgb(194, 12, 185);"><strong>cp</strong></span> <span style="font-weight: bold;">/</span>usr<span style="font-weight: bold;">/</span>share<span style="font-weight: bold;">/</span>zoneinfo<span style="font-weight: bold;">/</span>Asia<span style="font-weight: bold;">/</span>Shanghai <span style="font-weight: bold;">/</span>etc<span style="font-weight: bold;">/</span>localtime |