> 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-invalid-input.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# B.2. 處理無效或模稜兩可的時間戳記 \#

### B.2. 處理無效或模稜兩可的時間戳記 [#](#datetime-invalid-input) <a href="#datetime-invalid-input" id="datetime-invalid-input"></a>

一般而言，若日期／時間字串語法有效，但包含 超出範圍的欄位值，就會擲出錯誤。例如， 指定 2 月 31 日的輸入會被拒絕。

在日光節約時間轉換期間，看似有效的時間戳記字串 可能代表一個不存在或模稜兩可的 時間戳記。這類情況不會被拒絕；模稜兩可之處的解決方式是 決定要套用哪一個 UTC 偏移量。例如，假設 [TimeZone](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-TIMEZONE) 參數設定為 `America/New_York`，請看

```

=> SELECT '2018-03-11 02:30'::timestamptz;
      timestamptz
------------------------
 2018-03-11 03:30:00-04
(1 row)
```

由於那一天是該時區春季撥快時鐘的轉換日， 當地民用時間中並不存在凌晨 2:30 這個時刻；時鐘從 EST 凌晨 2 點 直接跳到 EDT 凌晨 3 點。PostgreSQL 會將 給定的時間當作標準時間（UTC-5）解讀，因此顯示為 EDT 凌晨 3:30（UTC-4）。

反之，請看秋季撥回時鐘轉換期間的行為：

```

=> SELECT '2018-11-04 01:30'::timestamptz;
      timestamptz
------------------------
 2018-11-04 01:30:00-05
(1 row)
```

在那一天，凌晨 1:30 有兩種可能的解讀：先是 EDT 凌晨 1:30，接著一小時後，時鐘從 EDT 凌晨 2 點撥回 EST 凌晨 1 點，又出現了 EST 凌晨 1:30。 同樣地，PostgreSQL 會將給定的時間 當作標準時間（UTC-5）解讀。我們可以透過 指定日光節約時間，強制採用另一種解讀：

```

=> SELECT '2018-11-04 01:30 EDT'::timestamptz;
      timestamptz
------------------------
 2018-11-04 01:30:00-04
(1 row)
```

這類情況所套用的精確規則是：看似落在 日光節約時間向前跳轉區間內的無效 時間戳記，會被指派該時區在 轉換前一刻所通行的 UTC 偏移量；而可能落在 向後跳轉兩側任一側的模稜兩可時間戳記，則會被指派 轉換後一刻所通行的 UTC 偏移量。在大多數時區中，這 等同於「有疑義時，優先採用標準時間的 解讀」。

在所有情況下，與時間戳記關聯的 UTC 偏移量都可以 明確指定，方法是使用數字 UTC 偏移量，或對應到 固定 UTC 偏移量的時區縮寫。剛才 說明的規則只適用於需要為偏移量會變動的時區 推斷 UTC 偏移量的情況。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/datetime-invalid-input.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-invalid-input.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.
