一、查看时间
使用'date'命令
ggm@ggm:~$ date
2023年 03月 06日 星期一 10:09:04 CST
ggm@ggm:~$ timedatectl status
Local time: 一 2023-03-06 02:11:16 UTC
Universal time: 一 2023-03-06 02:11:16 UTC
RTC time: 一 2023-03-06 02:11:17
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
二、想更改到中国北京时间
-
使用'tzselect',跟随'tzselect'工具进行配置
ggm@ggm:~$ tzselect
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 15) French Southern Territories 29) Kyrgyzstan 43) Russia
2) Antarctica 16) Georgia 30) Laos 44) Saudi Arabia
3) Armenia 17) Hong Kong 31) Lebanon 45) Seychelles
4) Azerbaijan 18) India 32) Macau 46) Singapore
5) Bahrain 19) Indonesia 33) Malaysia 47) Sri Lanka
6) Bangladesh 20) Iran 34) Mongolia 48) Syria
7) Bhutan 21) Iraq 35) Myanmar (Burma) 49) Taiwan
8) Brunei 22) Israel 36) Nepal 50) Tajikistan
9) Cambodia 23) Japan 37) Oman 51) Thailand
10) China 24) Jordan 38) Pakistan 52) Turkmenistan
11) Christmas Island 25) Kazakhstan 39) Palestine 53) United Arab Emirates
12) Cocos (Keeling) Islands 26) Korea (North) 40) Philippines 54) Uzbekistan
13) Cyprus 27) Korea (South) 41) Qatar 55) Vietnam
14) East Timor 28) Kuwait 42) Réunion 56) Yemen
#? 10
Please select one of the following timezones.
1) Beijing Time
2) Xinjiang Time, Vostok
#? 1
The following information has been given:
China
Beijing Time
Therefore TZ='Asia/Shanghai' will be used.
Selected time is now: 2023年 03月 06日 星期一 10:47:25 CST.
Universal Time is now: 2023年 03月 06日 星期一 02:47:25 UTC.
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/bin/tzselect command in shell scripts:
Asia/Shanghai
ggm@ggm:~$ TZ='Asia/Shanghai'; export TZ
-
还需要修改"/etc/profile"配置文件,在配置文件最后添加TZ='Asia/Shanghai'; export TZ
ggm@ggm:~$ sudo vim /etc/profile
[sudo] password for ggm:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
TZ='Asia/Shanghai'; export TZ
~
~
-
保存文件,并生效文件,然后重启服务器
root@ggm:~# source /etc/profile
root@ggm:~# reboot
root@ggm:~# date
2023年 03月 06日 星期一 10:57:14 CST
Ubuntu服务器时间设置完毕。