Ubunt20.04 修改时区
1、查看当前时间状态:
root@dbabackup:/usr/share/zoneinfo/Etc# timedatectl status
Local time: Thu 2022-09-08 15:08:27 CST
Universal time: Thu 2022-09-08 07:08:27 UTC
RTC time: Thu 2022-09-08 07:08:27
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
2、修改时间
所有的时区名称存储在/usr/share/zoneinfo文件中。
执行以下命令就可以将时区设为上海时区:
timedatectl set-timezone "Asia/Shanghai"
3.修改时间方法之二
root@dbabackup:/usr/share/zoneinfo/Etc# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa 7) Europe
2) Americas 8) Indian Ocean
3) Antarctica 9) Pacific Ocean
4) Asia 10) coord - I want to use geographical coordinates.
5) Atlantic Ocean 11) TZ - I want to specify the timezone using the Posix TZ format.
6) Australia
#? 4
Please select a country whose clocks agree with yours.
1) Afghanistan 15) French Southern & Antarctic Lands 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: Thu Sep 8 15:02:18 CST 2022.
Universal Time is now: Thu Sep 8 07:02:18 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/bin/tzselect command in shell scripts:
Asia/Shanghai
root@dbabackup:/usr/share/zoneinfo/Etc# date
Thu 08 Sep 2022 03:02:31 PM CST
root@dbabackup:/usr/share/zoneinfo/Etc# date -R
Thu, 08 Sep 2022 15:02:34 +0800
root@dbabackup:/usr/share/zoneinfo/Etc# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: '/usr/share/zoneinfo/Asia/Shanghai' and '/etc/localtime' are the same file
root@dbabackup:/usr/share/zoneinfo/Etc# date -R
Thu, 08 Sep 2022 15:03:03 +0800
####同步到硬件
root@dbabackup:/usr/share/zoneinfo/Etc# hwclock -w
root@dbabackup:/usr/share/zoneinfo/Etc#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏