Linux 时区修改

随笔记录,时区修改

1.使用命令:tzselect

1. 使用命令:tzselect在这里我们选择亚洲 Asia,确认之后选择中国(China),最后选择北京(Beijing)
[root@localhost ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.1) Africa2) Americas3) Antarctica4) Arctic Ocean5) Asia6) Atlantic Ocean7) Australia8) Europe9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.1) Afghanistan		  18) Israel		    35) Palestine2) Armenia		  19) Japan		    36) Philippines3) Azerbaijan		  20) Jordan		    37) Qatar4) Bahrain		  21) Kazakhstan	    38) Russia5) Bangladesh		  22) Korea (North)	    39) Saudi Arabia6) Bhutan		  23) Korea (South)	    40) Singapore7) Brunei		  24) Kuwait		    41) Sri Lanka8) Cambodia		  25) Kyrgyzstan	    42) Syria9) China		  26) Laos		    43) Taiwan
10) Cyprus		  27) Lebanon		    44) Tajikistan
11) East Timor		  28) Macau		    45) Thailand
12) Georgia		  29) Malaysia		    46) Turkmenistan
13) Hong Kong		  30) Mongolia		    47) United Arab Emirates
14) India		  31) Myanmar (Burma)	    48) Uzbekistan
15) Indonesia		  32) Nepal		    49) Vietnam
16) Iran		  33) Oman		    50) Yemen
17) Iraq		  34) Pakistan
#? 9
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 1The following information has been given:ChinaBeijing TimeTherefore TZ='Asia/Shanghai' will be used.
Local time is now:	Tue May 30 10:36:49 CST 2023.
Universal Time is now:	Tue May 30 02:36:49 UTC 2023.
Is the above information OK?
1) Yes
2) No
#? 1You can make this change permanent for yourself by appending the lineTZ='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 /bin/tzselect command in shell scripts:
Asia/Shanghai
[root@localhost ~]# root@localhost ~]# 
[root@localhost ~]# date
Mon May 29 22:37:03 EDT 20232.复制文件到/etc目录下
[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite ‘/etc/localtime’? Y
[root@localhost ~]# 3.再次查看时间date -R,已经修改为北京时间
[root@localhost ~]# date -R
Tue, 30 May 2023 10:38:00 +0800
[root@localhost ~]# 

2. Linux中查看有关时间的命令是date [选项] +[格式]

首先我们先看看单纯的date的输出结果,其中CST表示东八区

[root@localhost ~]# date
Tue May 30 11:31:03 CST 2023
[root@localhost ~]#
 

 3. 使用 timedatectl命令可以查看时区

[root@localhost ~]#
[root@localhost ~]# timedatectl
      Local time: Tue 2023-05-30 11:31:28 CST
  Universal time: Tue 2023-05-30 03:31:28 UTC
        RTC time: Tue 2023-05-30 03:31:28
       Time zone: America/New_York (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@localhost ~]#
 

4. 使用date -s "yyyy-MM-dd hh:mm:ss",例如将当前系统时间设置为2021年1月4日12:00:00则使用date -s "2021-01-04 12:00:00"


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部