Linux 修改时区

2019-07-13 06:58发布

方法1:使用tzselect设置时区
a 查看当前时区:date -R 系统目前时区是东八区 [root@localhost ~]# date -R Thu, 17 Nov 2016 23:27:24 +0800 b 将时区设置成纽约时间 tzselect =>2(Americas)=> 49(United States) =>1(Eastern Time),选定纽约时间,再选择1 确认 [root@localhost ~]# tzselect Please identify a location so that time zone rules can be set correctly. Please select a continent or ocean. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean 10) Pacific Ocean 11) none - I want to specify the time zone using the Posix TZ format. #? 2 Please select a country. 1) Anguilla 28) Haiti 2) Antigua & Barbuda 29) Honduras 3) Argentina 30) Jamaica 4) Aruba 31) Martinique 5) Bahamas 32) Mexico 6) Barbados 33) Montserrat 7) Belize 34) Nicaragua 8) Bolivia 35) Panama 9) Brazil 36) Paraguay 10) Canada 37) Peru 11) Caribbean Netherlands 38) Puerto Rico 12) Cayman Islands 39) St Barthelemy 13) Chile 40) St Kitts & Nevis 14) Colombia 41) St Lucia 15) Costa Rica 42) St Maarten (Dutch part) 16) Cuba 43) St Martin (French part) 17) Curacao 44) St Pierre & Miquelon 18) Dominica 45) St Vincent 19) Dominican Republic 46) Suriname 20) Ecuador 47) Trinidad & Tobago 21) El Salvador 48) Turks & Caicos Is 22) French Guiana 49) United States 23) Greenland 50) Uruguay 24) Grenada 51) Venezuela 25) Guadeloupe 52) Virgin Islands (UK) 26) Guatemala 53) Virgin Islands (US) 27) Guyana #? 49 Please select one of the following time zone regions. 1) Eastern Time 2) Eastern Time - Michigan - most locations 3) Eastern Time - Kentucky - Louisville area 4) Eastern Time - Kentucky - Wayne County 5) Eastern Time - Indiana - most locations 6) Eastern Time - Indiana - Daviess, Dubois, Knox & Martin Counties 7) Eastern Time - Indiana - Pulaski County 8) Eastern Time - Indiana - Crawford County 9) Eastern Time - Indiana - Pike County 10) Eastern Time - Indiana - Switzerland County 11) Central Time 12) Central Time - Indiana - Perry County 13) Central Time - Indiana - Starke County 14) Central Time - Michigan - Dickinson, Gogebic, Iron & Menominee Counties 15) Central Time - North Dakota - Oliver County 16) Central Time - North Dakota - Morton County (except Mandan area) 17) Central Time - North Dakota - Mercer County 18) Mountain Time 19) Mountain Time - south Idaho & east Oregon 20) Mountain Standard Time - Arizona (except Navajo) 21) Pacific Time 22) Alaska Time 23) Alaska Time - Alaska panhandle 24) Alaska Time - southeast Alaska panhandle 25) Alaska Time - Alaska panhandle neck 26) Alaska Time - west Alaska 27) Aleutian Islands 28) Metlakatla Time - Annette Island 29) Hawaii #? 1 The following information has been given: United States Eastern Time Therefore TZ='America/New_York' will be used. Local time is now: Thu Nov 17 10:29:55 EST 2016. Universal Time is now: Thu Nov 17 15:29:55 UTC 2016. Is the above information OK? 1) Yes 2) No #? 1 You can make this change permanent for yourself by appending the line TZ='America/New_York'; 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/bin/tzselect command in shell scripts: America/New_York c date -R 查看显示 当前时区是 东八区,修改并没有生效。
再执行 TZ=’America/New_York’; export TZ
执行 date -R 显示目前是 西五区,修改生效 [root@localhost ~]# date -R Thu, 17 Nov 2016 23:30:06 +0800 [root@localhost ~]# TZ='America/New_York'; export TZ [root@localhost ~]# date -R Thu, 17 Nov 2016 10:30:53 -0500 d 要想在下次开机时修改仍然有效,将 TZ=’America/New_York’; export TZ 添加到 .profile中,然后退出并重新登录 You can make this change permanent for yourself by appending the line TZ='America/New_York'; export TZ to the file '.profile' in your home directory; then log out and log in again. 2 通过修改配置文件修改时区 ``
[root@localhost ~]# date -R
Fri, 18 Nov 2016 00:30:46 +0800
[root@localhost ~]# cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
cp: overwrite
/etc/localtime’? y
[root@localhost ~]# date -R
Thu, 17 Nov 2016 08:31:02 -0800