linux時間和時區修改

來源:互聯網
上載者:User

標籤:linux 時間   時區   

1、查看系統時間

[[email protected] ~]# date
Thu Dec 20 23:25:33 CST 2012

[[email protected] ~]# date +"%Y%m%d %H:%m:%S"
20121220 23:12:54

2、查看硬體時間

系統時鐘是指當前Linux Kernel中的時鐘,而硬體時鐘則是主板上由電池供電的時鐘,這個硬體時鐘可以在BIOS中進行設定。當Linux啟動時,硬體時鐘會去讀取系統時鐘的設定,然後系統時鐘就會獨立於硬體運作。

[[email protected] ~]# hwclock 
Thu 20 Dec 2012 02:57:09 PM CST  -0.176702 seconds


[[email protected] ~]# clock
Thu 20 Dec 2012 02:57:14 PM CST  -0.575501 seconds

3、修改系統時間

[[email protected] ~]# date
Thu Dec 20 23:27:43 CST 2012
[[email protected] ~]# date -s "20121220 15:28:00"
Thu Dec 20 15:28:00 CST 2012
[[email protected] ~]# date
Thu Dec 20 15:28:03 CST 2012

4、修改硬體時間

[[email protected] ~]# hwclock 
Thu 20 Dec 2012 03:30:58 PM CST  -0.119534 seconds
[[email protected] ~]# hwclock --set --date="20121220 23:31:00"
[[email protected] ~]# hwclock 
Thu 20 Dec 2012 11:31:08 PM CST  -0.451844 seconds

5、系統時間與硬體時間之間的同步

系統時間同步到硬體時間:hwclock  -w  OR  hwclock -- systohc

硬體時間同步到系統時間:hwclock  -s   OR  hwclock -- hctosys

[[email protected] ~]# date
Thu Dec 20 15:39:08 CST 2012
[[email protected] ~]# hwclock 
Thu 20 Dec 2012 11:36:25 PM CST  -0.661838 seconds
[[email protected] ~]# hwclock -w
[[email protected] ~]# hwclock 
Thu 20 Dec 2012 03:39:25 PM CST  -0.090384 seconds

6、查看當前時區

[[email protected] ~]# date -R
Thu, 20 Dec 2012 15:41:24 +0800

[[email protected] ~]# cat /etc/sysconfig/clock |grep -i zone
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"

7、修改當前時區

方法一、[[email protected] ~]# timeconfig

介面化修改,僅適用於RHEL

方法二、修改/etc/localtime檔案,該檔案定義了Local Time Zone

[[email protected] ~]# date -R
Thu, 20 Dec 2012 15:46:51 +0800
[[email protected] ~]# mv /etc/localtime /etc/localtime.bak
[[email protected] ~]# cp /usr/share/zoneinfo/America/New_York /etc/localtime
[[email protected] ~]# date -R
Thu, 20 Dec 2012 02:47:40 -0500
[[email protected] ~]# cat /etc/sysconfig/clock |grep -i zone
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"

修改成功,但/etc/sysconfig/clock檔案中的timezone未變。

方法三、設定TZ環境變數

[[email protected] ~]# date -R
Thu, 20 Dec 2012 02:53:15 -0500
[[email protected] ~]# echo "export TZ=Asia/Shanghai" >>/etc/profile
[[email protected] ~]# cat /etc/profile |grep TZ
export TZ=Asia/Shanghai
[[email protected] ~]# source /etc/profile
[[email protected] ~]# date -R
Thu, 20 Dec 2012 15:54:47 +0800

$TZ環境變數的優先順序要比/etc/localtime要高,並且在設定該全域環境變數後,即使使用timeconfig來修改也一樣無法改變時區。

8、查看當前相應時區時間

查看-5區目前時間

[[email protected] ~]# zdump GMT-5
GMT-5  Thu Dec 20 12:59:13 2012 GMT

附相關縮寫含義

CST:CST同時可以代表如下 4 個不同的時區:

Central Standard Time (USA) UT-6:00

Central Standard Time (Australia) UT+9:30

China Standard Time UT+8:00

Cuba Standard Time UT-4:00

可見,CST可以同時表示美國,澳大利亞,中國,古巴四個國家的標準時間。

EDT - Eastern Daylight Time 東部夏令時間

 

CDT - Central Daylight Time 中部夏令時間

UTC:國際標準時間,又稱世界標準時間或世界協調時間,簡稱UTC,從英文“Coordinated Universal Time” 稱為世界統一時間。


linux時間和時區修改

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.