AT TIME ZONE Converts Both Directions

The same operator turns timestamptz into a zone local wall clock and turns a bare timestamp into an instant, with DST handled by IANA rules.

SqlData Integrity

Code

snippet
-- AT TIME ZONE 双向 converts:
-- 作用于 timestamptz -> 得到该时区的本地挂钟时间(timestamp)
-- 作用于 timestamp   -> 得到"这个本地时间在该时区"的 timestamptz
SELECT
    '2026-06-01 12:00:00+00'::timestamptz
        AT TIME ZONE 'Asia/Shanghai' AS shanghai_local,
    '2026-06-01 12:00:00'::timestamp
        AT TIME ZONE 'Asia/Shanghai' AS shanghai_instant;

-- 夏令时边界由数据库按 IANA 规则换算,不是固定偏移的数学
SELECT
    '2026-07-04 12:00:00+00'::timestamptz
        AT TIME ZONE 'America/New_York' AS ny_summer_local,
    '2026-01-04 12:00:00+00'::timestamptz
        AT TIME ZONE 'America/New_York' AS ny_winter_local;

-- 常见用法:存储统一 UTC,展示层按用户时区 converts
SELECT event_id, placed_at AT TIME ZONE 'Europe/Berlin' AS user_local_time
FROM events
ORDER BY placed_at
LIMIT 10;

What the code does

The file runs SELECT statements, touching events.

Mechanically, the statements are built from: an ORDER BY that fixes the output order; a row cap (LIMIT) bounding the result size.

Applying it

Run the statement against the events table; the LIMIT keeps the probe cheap while you tune the predicates.

Statements that matter

SELECT
    '2026-07-04 12:00:00+00'::timestamptz
        AT TIME ZONE 'America/New_York' AS ny_summer_local,
    '2026-01-04 12:00:00+00'::timestamptz
        AT TIME ZONE 'America/New_York' AS ny_winter_local;
SELECT
    '2026-06-01 12:00:00+00'::timestamptz
        AT TIME ZONE 'Asia/Shanghai' AS shanghai_local,
    '2026-06-01 12:00:00'::timestamp
        AT TIME ZONE 'Asia/Shanghai' AS shanghai_instant;
SELECT event_id, placed_at AT TIME ZONE 'Europe/Berlin' AS user_local_time
FROM events
ORDER BY placed_at
LIMIT 10;

Interactive Tools for This Topic

FAQ

Name the tables involved in this file.
The references are `events`.