> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/appendixes/datetime-appendix/datetime-posix-timezone-specs.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# B.5. POSIX 時區規格 \#

### B.5. POSIX 時區規格 [#](#datetime-posix-timezone-specs) <a href="#datetime-posix-timezone-specs" id="datetime-posix-timezone-specs"></a>

PostgreSQL 可以接受依照 POSIX 標準 對 `TZ` 環境變數所訂規則撰寫的 時區規格。POSIX 時區規格 不足以處理真實世界時區歷史的複雜性， 但有時仍有使用它們的理由。

POSIX 時區規格的形式為

```

STD offset [ DST [ dstoffset ] [ , rule ] ]
```

（為了方便閱讀，我們在欄位之間加上空格，但實際使用時 不應使用空格。）各欄位如下：

* *`STD`* 是用於 標準時間的時區縮寫。
* *`offset`* 是該時區的標準時間 與 UTC 的偏移量。
* *`DST`* 是用於 日光節約時間的時區縮寫。若省略此欄位及其後的欄位， 該時區會使用固定的 UTC 偏移量，沒有日光節約時間 規則。
* *`dstoffset`* 是日光節約時間 與 UTC 的偏移量。此欄位通常會省略，因為其預設值比 標準時間的 *`offset`* 少一小時， 這通常就是正確的值。
* *`rule`* 定義日光 節約時間何時生效的規則，如下文所述。

在此語法中，時區縮寫可以是一串英文字母，例如 `EST`，或是以角 括號括住的任意字串，例如 `<UTC-05>`。 請注意，這裡給定的時區縮寫只用於輸出， 而且即使是輸出，也只用於某些時間戳記輸出格式。時間戳記輸入中 可辨識的時區縮寫，其決定方式如 [第 B.4 節](https://docs.postgresql.tw/19/appendixes/datetime-appendix/datetime-config-files.md)所述。

偏移量欄位指定與 UTC 相差的小時數，以及可選的分鐘數與秒數。 其格式為 *`hh`*\[`:`*`mm`*\[`:`*`ss`*]]， 前面可以選擇加上正負號（`+` 或 `-`）。正號用於 格林威治以*西*的時區。（請注意，這與 PostgreSQL 其他地方所使用的 ISO-8601 正負號慣例 相反。）*`hh`* 可以是一位或兩位數字；*`mm`* 與 *`ss`*（若有使用）必須是兩位數字。

日光節約時間轉換 *`rule`* 的 格式為

```

dstdate [ / dsttime ] , stddate [ / stdtime ]
```

（與前述相同，實際使用時不應包含空格。） *`dstdate`* 與 *`dsttime`* 欄位定義日光節約 時間何時開始，而 *`stddate`* 與 *`stdtime`* 則定義標準時間 何時開始。（在某些情況下，特別是赤道以南的時區， 前者在一年中的日期可能晚於後者。）日期欄位 採用下列其中一種格式：

*`n`* : 單純的整數表示一年中的第幾天，從零計數到 364，閏年則到 365。

`J`*`n`* : 在此形式中，*`n`* 從 1 計數到 365， 且即使當年有 2 月 29 日也不計入。（因此， 發生在 2 月 29 日的轉換無法以此方式 指定。不過，2 月之後的日子無論是否為閏年， 編號都相同，因此對於固定日期的轉換，此形式通常 比單純整數形式更有用。）

`M`*`m`*`.`*`n`*`.`*`d`* : 此形式指定一個總是在同一個 月份、同一個星期幾發生的轉換。*`m`* 指定月份，從 1 到 12。*`n`* 指定由 *`d`* 所指定的星期幾的第 *`n`* 次出現。 *`n`* 是介於 1 到 4 之間的數字，或是 5， 表示該星期幾在該月中的最後一次出現（可能 是第四次或第五次）。*`d`* 是 介於 0 到 6 之間的數字，0 表示星期日。 例如，`M3.2.0` 表示「3 月的第二個 星期日」。

#### 注意

`M` 格式足以描述許多常見的 日光節約時間轉換法規。但請注意，這些變化形式都 無法處理日光節約時間法規的變更，因此實務上， 需要具名時區所儲存的歷史資料（位於 IANA 時區 資料庫中），才能正確解讀過去的時間戳記。

轉換規則中的時間欄位，格式與前面所述的偏移量 欄位相同，只是不能包含正負號。 它們定義切換到另一種 時間時的當前當地時間。若省略，預設為 `02:00:00`。

若給定了日光節約時間縮寫，但省略了 轉換 *`rule`* 欄位， 後備行為是使用 規則 `M3.2.0,M11.1.0`，它對應美國 截至 2020 年的做法（也就是在 3 月的第二個星期日撥快時鐘， 在 11 月的第一個星期日撥回時鐘，兩次轉換都 發生在當時通行時間的凌晨 2 點）。請注意，此規則 無法為 2007 年以前的年份提供正確的美國轉換日期。

舉例來說，`CET-1CEST,M3.5.0,M10.5.0/3` 描述了 巴黎目前（截至 2020 年）的計時做法。此規格 表示標準時間的縮寫為 `CET`， 比 UTC 快一小時（位於東方）；日光節約時間的 縮寫為 `CEST`，隱含比 UTC 快兩小時； 日光節約時間從 3 月的最後一個星期日 CET 凌晨 2 點 開始，並於 10 月的最後一個星期日 CEST 凌晨 3 點結束。

`EST5EDT`、 `CST6CDT`、`MST7MDT` 與 `PST8PDT` 這四個時區名稱看起來像是 POSIX 時區 規格。然而，它們實際上會被視為具名時區， 因為（由於歷史因素）IANA 時區資料庫中 有以這些名稱命名的檔案。其實際影響是， 這些時區名稱會產生有效的美國歷史日光節約時間 轉換，即使單純的 POSIX 規格無法做到。

需要留意的是，POSIX 風格的時區規格很容易拼錯， 因為系統不會檢查 時區縮寫是否合理。例如，`SET TIMEZONE TO FOOBAR0` 可以運作，結果系統實際上會使用一個 相當奇特的 UTC 縮寫。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/datetime-posix-timezone-specs.html)（原文版本：18.6；核對日期：2026-10-22）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/appendixes/datetime-appendix/datetime-posix-timezone-specs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
