Linux服务器修改时区时间

       时间的一致性很关键,对于日志的分析和程序的对接都至关重要!

01、tzselect 修改时区

可以使用命令 tzselect,修改时区。操作示例:

  1. $ tzselect
  2. Please identify a location so that time zone rules can be set correctly.
  3. Please select a continent or ocean.
  4. 1) Africa
  5. 2) Americas
  6. 3) Antarctica
  7. 4) Arctic Ocean
  8. 5) Asia
  9. 6) Atlantic Ocean
  10. 7) Australia
  11. 8) Europe
  12. 9) Indian Ocean
  13. 10) Pacific Ocean
  14. 11) none - I want to specify the time zone using the Posix TZ format.
  15. # 5 输入5,选择亚洲
  16. Please select a country.
  17. 1) Afghanistan 18) Israel 35) Palestine
  18. 2) Armenia 19) Japan 36) Philippines
  19. 3) Azerbaijan 20) Jordan 37) Qatar
  20. 4) Bahrain 21) Kazakhstan 38) Russia
  21. 5) Bangladesh 22) Korea (North) 39) Saudi Arabia
  22. 6) Bhutan 23) Korea (South) 40) Singapore
  23. 7) Brunei 24) Kuwait 41) Sri Lanka
  24. 8) Cambodia 25) Kyrgyzstan 42) Syria
  25. 9) China 26) Laos 43) Taiwan
  26. 10) Cyprus 27) Lebanon 44) Tajikistan
  27. 11) East Timor 28) Macau 45) Thailand
  28. 12) Georgia 29) Malaysia 46) Turkmenistan
  29. 13) Hong Kong 30) Mongolia 47) United Arab Emirates
  30. 14) India 31) Myanmar (Burma) 48) Uzbekistan
  31. 15) Indonesia 32) Nepal 49) Vietnam
  32. 16) Iran 33) Oman 50) Yemen
  33. 17) Iraq 34) Pakistan
  34. #9 输入9,选择中国
  35. Please select one of the following time zone regions.
  36. 1) east China - Beijing, Guangdong, Shanghai, etc.
  37. 2) Heilongjiang (except Mohe), Jilin
  38. 3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
  39. 4) most of Tibet & Xinjiang
  40. 5) west Tibet & Xinjiang
  41. #1 输入1,选择北京时间
  42. The following information has been given:
  43. China
  44. east China - Beijing, Guangdong, Shanghai, etc.
  45. Therefore TZ='Asia/Shanghai' will be used.
  46. Local time is now: Mon Nov 9 13:40:51 CST 2015.
  47. Universal Time is now: Mon Nov 9 05:40:51 UTC 2015.
  48. Is the above information OK?
  49. 1) Yes
  50. 2) No
  51. # 1 输入1确认
  52. You can make this change permanent for yourself by appending the line
  53. TZ='Asia/Shanghai'; export TZ
  54. to the file '.profile' in your home directory; then log out and log in again.
  55. Here is that TZ value again, this time on standard output so that you
  56. can use the /usr/bin/tzselect command in shell scripts:
  57. Asia/Shanghai

02、修改配置文件修改时区

也可以直接通过修改配置文件来变更时区。

  1. vi /etc/sysconfig/clock
  2. ZONE=Asia/Shanghai(查/usr/share/zoneinfo/Asia下面的文件)
  3. rm /etc/localtime
  4. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  #强制建立软链接
  5. 备注:修改完时区需要重启生效,查看时区可以使用命令 date -R。

03、修改同步时间

CST可视为美国,澳大利亚,古巴或中国的标准时间。
中文名
CST
概述 
CST可视为美国,澳大利
美国中部时间
Central Standard Time (USA)
中国标准时间
China Standard Time UT+8:00
古巴标准时间
Cuba Standard Time UT-4:00

UTC

协调世界时是以原子时秒长为基础,在时刻上尽量接近于世界时的一种时间计量系统

 linux系统时钟有两个:

一个是硬件时钟,即BIOS时间,就是我们进行CMOS设置时看到的时间,

一个是系统时钟,是linux系统Kernel时间。当Linux启动时,系统Kernel会去读取硬件时钟的设置,然后系统时钟就会独立于硬件运作。有时我们会发现系统时钟和硬件时钟不一致,因此需要执行时间同步.

 

系统时钟

date命令将日期设置为2014年6月18日

 ----   date -s 06/18/14

将时间设置为14点20分50秒

 ----   date -s 14:20:50

将时间设置为2014年6月18日14点16分30秒(MMDDhhmmYYYY.ss)

----date 0618141614.30

 

硬件时间

hwclock/clock 命令查看、设置硬件时间

查看系统硬件时钟

hwclock  --show  或 clock  --show

设置硬件时间

 hwclock --set --date="06/18/14 14:55" (月/日/年时:分:秒)

      clock --set --date="06/18/14 14:55" (月/日/年时:分:秒)

同步系统及硬件时钟

下图中可以看到硬件和系统时钟相差半小时。可以使用hwclock或者clock进行同步,

硬件时钟与系统时钟同步:

# hwclock --hctosys 或者 # clock --hctosys  hc代表硬件时间,sys代表系统时间,即用硬件时钟同步系统时钟

系统时钟和硬件时钟同步:

# hwclock --systohc或者# clock --systohc  即用系统时钟同步硬件时钟

posted @ 2017-07-25 20:10  mvpbang  阅读(6187)  评论(0编辑  收藏  举报