[root@testandy ~]# timedatectl --help
timedatectl [OPTIONS...] COMMAND ...
Query or change system time and date settings.
-h --help Show this help message
--version Show package version
--no-pager Do not pipe output into a pager
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--adjust-system-clock Adjust system clock when changing local RTC mode
Commands:
status Show current time settings
set-time TIME Set system time
set-timezone ZONE Set system time zone
list-timezones Show known time zones
set-local-rtc BOOL Control whether RTC is in local time
set-ntp BOOL Control whether NTP is enabled
設置時區同樣, 在 CentOS 7 中, 引入了一個叫 timedatectl 的設置設置程序.
用法很簡單:
timedatectl # 查看系統時間方面的各種狀態
$timedatectl status
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/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
timedatectl list-timezones # 列出所有時區 timedatectl set-local-rtc 1 # 將硬件時鍾調整為與本地時鍾一致, 0 為設置為 UTC 時間 timedatectl set-timezone Asia/Shanghai # 設置系統時區為上海
其實不考慮各個發行版的差異化, 從更底層出發的話, 修改時間時區比想象中要簡單:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime