Linux时区

查看时区

1
date -R

-0800 : 表示西八区,是美国旧金山所在的时区
+0800 : 我们国家的东八区

设置时区

通过修改环境变量设置

1
2
3
tzselect
echo "TZ='Asia/Shanghai'; export TZ" >> .profile
source .profile

通过交互式的方式获得参数,然后修改 .profile.bash_profile 等环境变量内容 TZ='Asia/Shanghai'; export TZ 来设置,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[root@localhost ~]# ttzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa
2) Americas
3) Antarctica
4) Asia
5) Atlantic Ocean
6) Australia
7) Europe
8) Indian Ocean
9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the timezone using the Posix TZ format.
#? 4
Please select a country whose clocks agree with yours.
1) Afghanistan 18) Iraq 35) Pakistan
2) Antarctica 19) Israel 36) Palestine
3) Armenia 20) Japan 37) Philippines
4) Azerbaijan 21) Jordan 38) Qatar
5) Bahrain 22) Kazakhstan 39) Russia
6) Bangladesh 23) Korea (North) 40) Saudi Arabia
7) Bhutan 24) Korea (South) 41) Singapore
8) Brunei 25) Kuwait 42) Sri Lanka
9) Cambodia 26) Kyrgyzstan 43) Syria
10) China 27) Laos 44) Taiwan
11) Cyprus 28) Lebanon 45) Tajikistan
12) East Timor 29) Macau 46) Thailand
13) Georgia 30) Malaysia 47) Turkmenistan
14) Hong Kong 31) Mongolia 48) United Arab Emirates
15) India 32) Myanmar (Burma) 49) Uzbekistan
16) Indonesia 33) Nepal 50) Vietnam
17) Iran 34) Oman 51) Yemen
#? 10
Please select one of the following timezones.
1) Beijing Time
2) Xinjiang Time
#? 1

The following information has been given:

China
Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now: Sun Mar 6 19:20:49 CST 2022.
Universal Time is now: Sun Mar 6 11:20:49 UTC 2022.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/sbin/tzselect command in shell scripts:
Asia/Shanghai

通过复制或链接时区文件修改

1
2
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

若无 zoneinfo 目录,则需要安装 timezone 数据包 tzdata

通过 timeconfig 设置

timeconfig 命令仅限于RedHatCentOS

—arc : 使用Alpha硬件结构的格式存储系统时间
—back : 在互动式界面里,显示Back钮而非Cancel钮
—test : 仅作测试,并不真的改变系统的时区
—utc : 把硬件时钟上的时间视为CUT,有时也称为UTC或UCT

-------------本文结束感谢阅读-------------

欢迎关注我的其它发布渠道