Linux服务器修改时区时间

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

0一、tzselect 修改时区

能够使用命令 tzselect,修改时区。操做示例:web

  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

0二、修改配置文件修改时区

也能够直接经过修改配置文件来变动时区。shell

  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。

0三、修改同步时间

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

UTCapp

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

 linux系统时钟有两个:ui

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

一个是系统时钟,是linux系统Kernel时间。当Linux启动时,系统Kernel会去读取硬件时钟的设置,而后系统时钟就会独立于硬件运做。有时咱们会发现系统时钟和硬件时钟不一致,所以须要执行时间同步.url

 

系统时钟spa

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  即用系统时钟同步硬件时钟

相关文章
相关标签/搜索