您当前的位置:首页 > 计算机 > 系统应用 > Linux

Ubuntu修改时区,调整正确时间最简单的方法

时间:05-08来源:作者:点击数:

本地时间正确,但是时区不对:

root@mirror:/home/mirror# 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 time zone using the Posix TZ format.
    #? 4
    Please select a country whose clocks agree with yours.
  12. Afghanistan 18) Israel 35) Palestine
  13. Armenia 19) Japan 36) Philippines
  14. Azerbaijan 20) Jordan 37) Qatar
  15. Bahrain 21) Kazakhstan 38) Russia
  16. Bangladesh 22) Korea (North) 39) Saudi Arabia
  17. Bhutan 23) Korea (South) 40) Singapore
  18. Brunei 24) Kuwait 41) Sri Lanka
  19. Cambodia 25) Kyrgyzstan 42) Syria
  20. China 26) Laos 43) Taiwan
  21. Cyprus 27) Lebanon 44) Tajikistan
  22. East Timor 28) Macau 45) Thailand
  23. Georgia 29) Malaysia 46) Turkmenistan
  24. Hong Kong 30) Mongolia 47) United Arab Emirates
  25. India 31) Myanmar (Burma) 48) Uzbekistan
  26. Indonesia 32) Nepal 49) Vietnam
  27. Iran 33) Oman 50) Yemen
  28. Iraq 34) Pakistan
    #? 9
    Please select one of the following time zone regions.
  29. Beijing Time
  30. Xinjiang Time
    #? 1

The following information has been given:

    China
    Beijing Time

Therefore TZ=‘Asia/Shanghai’ will be used.

Selected time is now: Fri Dec 31 13:40:43 CST 2021.

Universal Time is now: Fri Dec 31 05:40:43 UTC 2021.

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@mirror:/home/mirror:~$ date

Fri Dec 31 05:39:06 UTC 2021

修改完成后,发现时区还是不正确。按网上的方法cp:

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

root@mirror:/home/mirror# date -R

Fri, 31 Dec 2021 14:01:03 +0800

vi /etc/localtime

发现最大的变化是时区变了

CST0 ---->CST-8

下次直接vi /etc/localtime 修改时区试试。

以上是时间正确,时区不对的处理方法。

如果是本地时间本身就不正确,方法如下

date -s MM/DD/YY //修改日期

date -s hh:mm:ss //修改时间

在修改时间以后,还要修改硬件CMOS的时间,方法如下:

hwclock --systohc //非常重要,如果没有这一步的话,后面时间还是不准

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门