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

# 8.5.2. 日期／時間輸出

## 8.5.2. 日期／時間輸出 [#](#datatype-datetime-output) <a href="#datatype-datetime-output" id="datatype-datetime-output"></a>

日期／時間型別的輸出格式，可以設定為以下 四種風格之一：ISO 8601、 SQL（Ingres）、傳統的 POSTGRES （Unix 日期格式），或 German（德式）。預設值 是 ISO 格式。（SQL 標準 要求使用 ISO 8601 格式。 「SQL」這個輸出格式的名稱， 是一段歷史上的巧合。）[表 8.14](#datatype-datetime-output-table) 展示了 每一種輸出風格的範例。`date` 型別與 `time` 型別的輸出，通常只會依照給定範例， 只顯示日期或時刻的部分。不過， POSTGRES 風格會以 ISO 格式輸出僅含日期的值。

### 表 8.14. 日期／時間輸出風格 [#](#datatype-datetime-output-table) <a href="#datatype-datetime-output-table" id="datatype-datetime-output-table"></a>

| 風格規格       | 說明              | 範例                             |
| ---------- | --------------- | ------------------------------ |
| `ISO`      | ISO 8601，SQL 標準 | `1997-12-17 07:37:16-08`       |
| `SQL`      | 傳統風格            | `12/17/1997 07:37:16.00 PST`   |
| `Postgres` | 原始風格            | `Wed Dec 17 07:37:16 1997 PST` |
| `German`   | 地區風格            | `17.12.1997 07:37:16.00 PST`   |

<br>

### 注意 [#](#zhu-yi-1) <a href="#zhu-yi-1" id="zhu-yi-1"></a>

ISO 8601 規定使用大寫字母 `T`， 來分隔日期與時刻。PostgreSQL 在輸入時 接受這種格式，但在輸出時，如上所示， 會使用空白而非 `T`。這是為了 提高可讀性，並與 [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) 以及其他一些資料庫系統保持一致。

在 SQL 與 POSTGRES 風格中， 若指定了 DMY 欄位順序，日會出現在 月之前，否則月會出現在 日之前。 （關於此設定如何同時影響輸入值的解讀方式， 請參閱[8.5.1 節](https://docs.postgresql.tw/19/the-sql-language/datatype/datatype-datetime/datatype-datetime-input.md#datatype-datetime-input)。） [表 8.15](#datatype-datetime-output2-table) 展示了一些範例。

### 表 8.15. 日期順序慣例 [#](#datatype-datetime-output2-table) <a href="#datatype-datetime-output2-table" id="datatype-datetime-output2-table"></a>

| `datestyle` 設定  | 輸入順序                       | 範例輸出                           |
| --------------- | -------------------------- | ------------------------------ |
| `SQL, DMY`      | *`day`*/*`month`*/*`year`* | `17/12/1997 15:37:16.00 CET`   |
| `SQL, MDY`      | *`month`*/*`day`*/*`year`* | `12/17/1997 07:37:16.00 PST`   |
| `Postgres, DMY` | *`day`*/*`month`*/*`year`* | `Wed 17 Dec 07:37:16 1997 PST` |

<br>

在 ISO 風格中，時區永遠會以一個 帶正負號的數值偏移量表示，相對於 UTC， 格林威治以東的時區使用正號。若時區偏移量 是整數小時，則會顯示為 *`hh`*（僅小時）；若是整數分鐘， 則顯示為 *`hh`*:*`mm`*；否則 顯示為 *`hh`*:*`mm`*:*`ss`*。 （第三種情況，在任何現代時區標準下都不可能出現， 但在處理早於標準化時區採用之前的時間戳記時， 可能會出現。） 在其他日期風格中，若目前時區有常用的字母縮寫， 時區就會以該字母縮寫顯示。否則 會以 ISO 8601 基本格式中， 帶正負號的數值偏移量顯示 （*`hh`* 或 *`hhmm`*）。 這些風格中所顯示的字母縮寫， 是取自 [TimeZone](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-TIMEZONE) 執行時期參數 目前所選擇的 IANA 時區資料庫項目；它們 不受 [timezone\_abbreviations](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-TIMEZONE-ABBREVIATIONS) 設定的影響。

使用者可以透過 `SET datestyle` 指令、 `postgresql.conf` 組態檔中的 [DateStyle](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-DATESTYLE) 參數， 或伺服器或用戶端上的 `PGDATESTYLE` 環境變數， 來選擇日期／時間風格。

格式化函式 `to_char` （請參閱[9.8 節](https://docs.postgresql.tw/19/the-sql-language/functions/functions-formatting.md)）， 也提供了一種更靈活的方式， 來格式化日期／時間輸出。

[返回 8.5. 日期／時間型別](https://docs.postgresql.tw/19/the-sql-language/datatype/datatype-datetime.md#datatype-datetime)

***

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


---

# 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/the-sql-language/datatype/datatype-datetime/datatype-datetime-output.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.
