almost 4 years ago

故事發生在有一次同事要改變時區的時候,為了要讓設定變簡單,決定暫時使用時區的數字來改變系統時區。當我們下了指令:

$ dpkg-reconfigure tzdata

卻發現並不能直接選數字,仔細一瞧原來有個 Etc,難道是傳說中的「其他」。很開心的點進去,就發現

Awesome! 這不就是我們需要的選項。馬上就選了 GMT+8 來測試一下。

這...與我想的不大一樣,仔細看看似乎差了 16 小時。

Etc/GMT

根據 Wiki Tz Database 的說法:

Area is the name of a continent, an ocean, or "Etc". The continents and oceans currently include: Africa, America, Antarctica, Arctic, Asia, Atlantic, Australia, Europe, Indian, and Pacific.

The special area of "Etc" is used for some administrative zones, particularly for "Etc/UTC" which represents Coordinated Universal Time. In order to conform with the POSIX style, those zone names beginning with "Etc/GMT" have their sign reversed from what most people expect. In this style, zones west of GMT have a positive sign and those east have a negative sign in their name (e.g "Etc/GMT-14" is 14 hours ahead/east of GMT.)

Etc 後面接著的 GMT 偏移量是與現實中相反的。也就是以正數表示格林威治 (Greenwich) 以西,以負數表示格林威治以東。

由來

因為 POSIX 時區格式定義了不同的方向時區偏移量。(主要的原因是當初 Unix 的開發者幾乎都在美國,而他們以正數來表示他們所在地與格林威治的偏移量。)

The POSIX TZ string takes the following form:

stdoffset[dst[offset][,date[/time],date[/time]]]

where:

std and dst are 3 or more characters specifying the standard and daylight saving time (DST) zone names. Starting with POSIX.1-2001, std and dst may also be in a quoted form like <UTC+10>; this allows "+" and "-" in the names.

offset is of the form '[+-]hh:[mm[:ss]]' and specifies the offset west of UT. 'hh' may be a single digit; 0<=hh<=24. The default DST offset is one hour ahead of standard time.

在設定時區時,若無法以區域來表示時區,只好以偏移量來作計算,因此也就有了 GMT+1, GMT+2, ...。為了不要讓使用者將之與一般的時區方向搞混,當時的開法者就決定用 Etc 這個資料夾把這些數字時區裝起來,也就有了一開始提到的這些選項。

參考資料

  1. Why does TZ=UTC-8 produce dates that are UTC+8?
  2. Understand the POSIX format
  3. Definition of POSIX TZ
  4. IETF Timezone Etc
← Django 上傳中文檔名 SublimeLinter3 介紹 →
 
comments powered by Disqus