linux 設定時區

2021-09-08 02:12:01 字數 3079 閱讀 1824

時間以及時區設定

首先確認使用utc還是local time. 

utc(universal time coordinated)=gmt(greenwich mean time) 

local time 是你手錶上的時間

傳統的posix計算機(solaris,bsd,unix)使用utc格式 

linux可以處理utc時間和蹩腳的windows所使用的local time

1) 使用cat /etc/sysconfig/clock檢視當前時區 

linux5:~ # cat /etc/sysconfig/clock

## path:                system/environment/clock

## description:         information about your timezone and time

## type:                string

## servicerestart:      boot.clock

## set to "-u" if your system clock is set to utc, and to "--localtime"

# if your clock runs that way.

#hwclock="-u"

## type:                string(europe/berlin,europe/london,europe/paris)

## servicerestart:      boot.clock

## timezone (e.g. cet)

# (this will set /usr/lib/zoneinfo/localtime)

#timezone="us/pacific"

default_timezone="us/pacific"

linux5:~ #

2) 使用tzselect設定時區,最後結果如下

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

linux5:~ #

3) 複製相應的時區檔案,替換系統預設時區 

linux5:~ # cp /usr/share/zoneinfo/asia/shanghai /etc/localtime

linux5:~ #

4) 將當前時間寫入bios永久生效(避免重啟後失效) 

linux5:~ # hwclock

tue jan 29 18:22:59 2008  -0.565688 seconds

linux5:~ #

server 10.30.1.105

檢視ntp服務的狀態

linux:/var/log # /etc/init.d/xntpd  status

checking for network time protocol daemon (ntpd):                    unused

設定時區以及時間

/usr/sbin/zic -l prc

/bin/date "+%h:%m:%s - %d-%m-%y"

寫回硬體時鐘

/sbin/hwclock --hctosys --localtime

或者寫回硬體時鐘: hwclock --systohc

在/etc/rc.d/rc5.d建立xntp服務的啟動指令碼

linux:/etc/rc.d/rc5.d # ln -s ../xntpd s14xntpd

檢視ntp時間調整紀錄

linux:/var/log # grep ntp messages

aug 14 07:19:51 linux ntpdate[2837]: step time server 10.30.1.105 offset 2.010174 sec

aug 14 07:19:51 linux ntpd[2884]: ntpd [email protected] wed jun 30 18:37:03 utc 2004 (1)

aug 14 07:19:51 linux ntpd[2884]: precision = 1.000 usec

aug 14 07:19:51 linux ntpd[2884]: listening on inte***ce wildcard, 0.0.0.0#123

aug 14 07:19:51 linux ntpd[2884]: listening on inte***ce wildcard, ::#123

aug 14 07:19:51 linux ntpd[2884]: listening on inte***ce lo, 127.0.0.1#123

aug 14 07:19:51 linux ntpd[2884]: listening on inte***ce eth0, 10.40.157.66#123

aug 14 07:19:51 linux ntpd[2884]: kernel time sync status 0040

mmscbill:~ # date

wed may  7 15:53:10 cst 2008

這裡時區設定沒有錯. prc是時區的名稱,它對應/usr/share/lib/zoneinfo下的prc時區檔案.

cst是chinese standard time的縮寫,用在date命令的輸出中.它是定義在prc時區檔案中.看

一下/usr/share/lib/zoneinfo/src下的asia檔案就知道是怎麼回事了.

修改系統時間(bjchenxu,laixi781211,hutuworm)

date -s 「2003-04-14 cst」,cst指時區,時間設定用date -s 18:10

修改後執行clock -w 寫到cmos

hwclock --systohc

set the hardware clock to the current system time

zdump -v europe/moscow 檢視時區一些設定引數

linux時區設定

本宣告 時間以及時區設定 首先確認使用utc還是local time.utc universal time coordinated gmt greenwich mean time local time 是你手錶上的時間 傳統的posix計算機 solaris,bsd,unix 使用utc格式 lin...

linux 時區設定

local vs.utc 首先重要的問題是你使用utc還是local time.utc universal time coordinated gmt greenwich mean time local time 是你手錶上的時間 傳統的posix計算機 solaris,bsd,unix 使用utc格...

linux設定時區

linux系統時區設定 開始設定時區時,參考網上的資料,使用tzselect 命令來進行,結果發現tzselect命令只是告訴了設定時區的方法,而並不是真的去修改 etc sysconfig clock這個檔案。換句話說就是tzselect命令僅僅告訴我們通過設定tz這個環境變數來選擇的時區,然後將...