VPS修改时区方法→怎样修改linux云服务器系统的时区?
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |
前言如果你的 Linux 系统时区配置不正确,必需要手动调整到正确的当地时区。NTP 对时间的同步处理只计算当地时间与 UTC 时间的偏移量,因此配置一个 NTP 对时间进行同步并不能解决时区不正确的问题。所以大家在用了国外云计算服务商如 Microsoft Azure 或其它 VPS、虚拟机时,需要注意是否与中国大陆的时区一致。
教程查看Linux当前时区
你可以使用如下命令非常容易地就查看到 Linux 系统的当前时区:
root@mcheng:~# dateMon 09 May 2022 02:24:05 AM EDTroot@mcheng:~# ls -l /etc/localtimelrwxrwxrwx 1 root root 30 Aug 16 2021 /etc/localtime -> /usr/share/zoneinfo/US/Easternroot@mcheng:~# dateMon 09 May 2022 02:24:05 AM EDTroot@mcheng:~# ls -l /etc/localtimelrwxrwxrwx 1 root root 30 Aug 16 2021 /etc/localtime -> /usr/share/zoneinfo/US/Easternroot@mcheng:~# dateMon 09 May 2022 02:24:05 AM EDTroot@mcheng:~# ls -l /etc/localtimelrwxrwxrwx 1 root root 30 Aug 16 2021 /etc/localtime -> /usr/share/zoneinfo/US/Eastern获取时区TZ值
要更改 Linux 系统时区首先得获知你所当地时区的 TZ 值,使用 tzselect 命令即可查看并选择已安装的时区文件。
执行 tzselect 命令:
root@DMIT-SIeyeophVm:~# tzselectPlease identify a location so that time zone rules can be set correctly.Please select a continent, ocean, "coord", or "TZ".1) Africa 7) Europe2) Americas 8) Indian Ocean3) Antarctica 9) Pacific Ocean4) Asia 10) coord - I want to use geographical coordinates.5) Atlantic Ocean 11) TZ - I want to specify the time zone using the Posix TZ format.6) Australia#? 4 //通过向导选择你所在大洲Please select a country whose clocks agree with yours.1) Afghanistan 10) Cyprus 19) Japan 28) Macau 37) Qatar 46) Turkmenistan2) Armenia 11) East Timor 20) Jordan 29) Malaysia 38) Russia 47) United Arab Emirates3) Azerbaijan 12) Georgia 21) Kazakhstan 30) Mongolia 39) Saudi Arabia 48) Uzbekistan4) Bahrain 13) Hong Kong 22) Korea (North) 31) Myanmar (Burma) 40) Singapore 49) Vietnam5) Bangladesh 14) India 23) Korea (South) 32) Nepal 41) Sri Lanka 50) Yemen6) Bhutan 15) Indonesia 24) Kuwait 33) Oman 42) Syria7) Brunei 16) Iran 25) Kyrgyzstan 34) Pakistan 43) Taiwan8) Cambodia 17) Iraq 26) Laos 35) Palestine 44) Tajikistan9) China 18) Israel 27) Lebanon 36) Philippines 45) Thailand#? 9 //通过向导选择你所在国家Please select one of the following time zone regions.1) Beijing Time2) Xinjiang Time#? 1 //通过向导选择你所在城市The following information has been given: China Beijing TimeTheore TZ='Asia/Shanghai' will be used.Selected time is now: Mon May 9 14:22:16 CST 2022.Universal Time is now: Mon May 9 06:22:16 UTC 2022.Is the above information OK?1) Yes2) No#? 1 //通过导向确认时间是否正确You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZto 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 youcan use the /usr/bin/tzselect command in shell scripts:Asia/Shanghai //确认时区信息root@DMIT-SIeyeophVm:~# tzselectPlease identify a location so that time zone rules can be set correctly.Please select a continent, ocean, "coord", or "TZ".1) Africa 7) Europe2) Americas 8) Indian Ocean3) Antarctica 9) Pacific Ocean4) Asia 10) coord - I want to use geographical coordinates.5) Atlantic Ocean 11) TZ - I want to specify the time zone using the Posix TZ format.6) Australia#? 4 //通过向导选择你所在大洲Please select a country whose clocks agree with yours.1) Afghanistan 10) Cyprus 19) Japan 28) Macau 37) Qatar 46) Turkmenistan2) Armenia 11) East Timor 20) Jordan 29) Malaysia 38) Russia 47) United Arab Emirates3) Azerbaijan 12) Georgia 21) Kazakhstan 30) Mongolia 39) Saudi Arabia 48) Uzbekistan4) Bahrain 13) Hong Kong 22) Korea (North) 31) Myanmar (Burma) 40) Singapore 49) Vietnam5) Bangladesh 14) India 23) Korea (South) 32) Nepal 41) Sri Lanka 50) Yemen6) Bhutan 15) Indonesia 24) Kuwait 33) Oman 42) Syria7) Brunei 16) Iran 25) Kyrgyzstan 34) Pakistan 43) Taiwan8) Cambodia 17) Iraq 26) Laos 35) Palestine 44) Tajikistan9) China 18) Israel 27) Lebanon 36) Philippines 45) Thailand#? 9 //通过向导选择你所在国家Please select one of the following time zone regions.1) Beijing Time2) Xinjiang Time#? 1 //通过向导选择你所在城市The following information has been given: China Beijing TimeTheore TZ='Asia/Shanghai' will be used.Selected time is now: Mon May 9 14:22:16 CST 2022.Universal Time is now: Mon May 9 06:22:16 UTC 2022.Is the above information OK?1) Yes2) No#? 1 //通过导向确认时间是否正确You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZto 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 youcan use the /usr/bin/tzselect command in shell scripts:Asia/Shanghai //确认时区信息root@DMIT-SIeyeophVm:~# tzselectPlease identify a location so that time zone rules can be set correctly.Please select a continent, ocean, "coord", or "TZ".1) Africa 7) Europe2) Americas 8) Indian Ocean3) Antarctica 9) Pacific Ocean4) Asia 10) coord - I want to use geographical coordinates.5) Atlantic Ocean 11) TZ - I want to specify the time zone using the Posix TZ format.6) Australia#? 4 //通过向导选择你所在大洲Please select a country whose clocks agree with yours.1) Afghanistan 10) Cyprus 19) Japan 28) Macau 37) Qatar 46) Turkmenistan2) Armenia 11) East Timor 20) Jordan 29) Malaysia 38) Russia 47) United Arab Emirates3) Azerbaijan 12) Georgia 21) Kazakhstan 30) Mongolia 39) Saudi Arabia 48) Uzbekistan4) Bahrain 13) Hong Kong 22) Korea (North) 31) Myanmar (Burma) 40) Singapore 49) Vietnam5) Bangladesh 14) India 23) Korea (South) 32) Nepal 41) Sri Lanka 50) Yemen6) Bhutan 15) Indonesia 24) Kuwait 33) Oman 42) Syria7) Brunei 16) Iran 25) Kyrgyzstan 34) Pakistan 43) Taiwan8) Cambodia 17) Iraq 26) Laos 35) Palestine 44) Tajikistan9) China 18) Israel 27) Lebanon 36) Philippines 45) Thailand#? 9 //通过向导选择你所在国家Please select one of the following time zone regions.1) Beijing Time2) Xinjiang Time#? 1 //通过向导选择你所在城市The following information has been given: China Beijing TimeTheore TZ='Asia/Shanghai' will be used.Selected time is now: Mon May 9 14:22:16 CST 2022.Universal Time is now: Mon May 9 06:22:16 UTC 2022.Is the above information OK?1) Yes2) No#? 1 //通过导向确认时间是否正确You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZto 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 youcan use the /usr/bin/tzselect command in shell scripts:Asia/Shanghai //确认时区信息tzselect 最终将以 Posix TZ 格式(例如 Asia/Shanghai)输出你所在的时区值,将此记录下来,然后执行:
TZ='Asia/Shanghai'; export TZTZ='Asia/Shanghai'; export TZTZ='Asia/Shanghai'; export TZ执行完成之后需要重新登录系统或刷新 ~/.bashrc 生效:
ource ~/.bashrcource ~/.bashrcource ~/.bashrc检验系统当前时间:
root@DMIT-SIeyeophVm:~# dateMon 09 May 2022 02:28:56 PM CSTroot@DMIT-SIeyeophVm:~# dateMon 09 May 2022 02:28:56 PM CSTroot@DMIT-SIeyeophVm:~# dateMon 09 May 2022 02:28:56 PM CST然后在执行:
sudo rm -f /etc/localtimesudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtimesudo rm -f /etc/localtimesudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtimesudo rm -f /etc/localtimesudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime使用Systemd更改Linux系统时区
如果你使用的 Linux 系统使用 Systemd,还可以使用 timedatectl 命令来更改 Linux 系统范围的时区。在 Systemd 下有一个名为 systemd-timedated 的系统服务负责调整系统时钟和时区,我们可以使用 timedatectl 命令对此系统服务进行配置:
[root@lax ~]# sudo timedatectl set-timezone 'Asia/Shanghai'[root@lax ~]# datetimecal Local time: Mon 2022-05-09 15:10:51 CST Universal time: Mon 2022-05-09 07:10:51 UTC RTC time: Mon 2022-05-09 07:08:53 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yesNTP synchronized: yes RTC in local TZ: no DST active: n/a[root@lax ~]# dateMon May 9 15:11:14 CST 2022[root@lax ~]# sudo timedatectl set-timezone 'Asia/Shanghai'[root@lax ~]# datetimecal Local time: Mon 2022-05-09 15:10:51 CST Universal time: Mon 2022-05-09 07:10:51 UTC RTC time: Mon 2022-05-09 07:08:53 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yesNTP synchronized: yes RTC in local TZ: no DST active: n/a[root@lax ~]# dateMon May 9 15:11:14 CST 2022[root@lax ~]# sudo timedatectl set-timezone 'Asia/Shanghai'[root@lax ~]# datetimecal Local time: Mon 2022-05-09 15:10:51 CST Universal time: Mon 2022-05-09 07:10:51 UTC RTC time: Mon 2022-05-09 07:08:53 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yesNTP synchronized: yes RTC in local TZ: no DST active: n/a[root@lax ~]# dateMon May 9 15:11:14 CST 2022[免费VPS]历史优惠活动内容
猜你可能想看的VPS
- CMIVPS→$8.3 月 KVM-2GB 10G SSD 3M 无限 香港VPS[主机]
- 线路不行-Sentris→$24.99 3 年 512MB 内存 20G虚拟空间(主机)
- Krypt→iON 品牌 快闪优惠来袭 过时不候[机房直营|稳定建站|C全球[VPS测评]
- 大硬盘 €15 年 512M 内存 128G 硬盘 500G 流量 1G全球[VPS测评]
- LOCVPS 香港邦联全新套餐,高性价比 Cn2 线路,2 核 2G 内香港VPS[主机]
- YonZy→66 元 年 512MB 内存 6GB SSD 空间 不限流虚拟空间(主机)
- mysql 替换字段指定内容的方法全球[VPS测评]
- 七月优惠 ZJI→全新上线 香港云地国际 VDS 七折优惠 所有 VPS香港VPS[主机]
- racknerd→60Gbps 高防(sharktech 鲨鱼洛杉矶机房全球[VPS测评]
- 做站 微基主机→香港 CN2 直连机房虚拟主机 速度媲美国内 最低年付 美国VPS[主机]
- Yourwebhoster→€3.95 月 1GB 内存 20GB SS虚拟空间(主机)
- stsdust 广州移动 vds 预售,1Gbps 带宽无限流量,硬件资全球[VPS测评]
- 真实测评 修罗云→洛杉矶 CN2 GIA 线路 1G 内存方案测评数据全球[VPS测评]
- 宝塔面板 nginx 安装的 wordpress 或者 typecho 全球[VPS测评]
- 君子下面有一个大的梁字是什么成语?全球[VPS测评]
- 优化YSlow add expires headers项目提升博客访问速全球[VPS测评]
- 微基主机:洛杉矶 Cera CU4837 和CU9929 KVM VPS全球[VPS测评]
- CLOUDKU 7.8$ 月 印度尼西亚 1C1G20G硬盘 100M带全球[VPS测评]
- 昱格云 1核心 1024 MB内存 10G SSD 1T单向流量 100全球[VPS测评]
- 什么是VPS?国内VPS有哪些?全球[VPS测评]
- 如何更改WHMCS默认后台路径让WHMCS系统更安全全球[VPS测评]
- 很简单的图片不规则布局样式,纯css样式实现的图片瀑布流布局全球[VPS测评]
- 2022年亚马逊Prime会员日将于7月12日和13日举行,覆盖24个站全球[VPS测评]
- 印象云,香港安畅CN2VPS终身8折1核1G22元/月,美国CN2高防V美国VPS[主机]
- CubeCloud,靠谱的香港cn2vps,美国cn2终身九折,原生IP美国VPS[主机]
- 中国跨境电商,如何掘金欧洲市场?全球[VPS测评]
- pigyun:韩国CN2云服务器仅14元;香港CN2建站vps特惠+美国韩国VPS[主机]
- 日主机,便宜美国CN2高防VPS¥19/月起,1Gbps带宽,香港多IP站群服务器[IP]
- 云米科技:香港/美国/日本等海外免备案vps云服务器,最低13元/月日本VPS[主机]
- 桔子数据怎么样?美国、香港CN2云服务器2核2G10M带宽仅480元/年美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-164207.html











