Returns the IANA time zone name or GMT offset string for a given point.
Syntax
cstring ST_TimeZone(geometry point, boolean timezoneId, integer timezonePrecision);
cstring ST_TimeZone(geography point, boolean timezoneId, integer timezonePrecision);Parameters
| Parameter | Description |
|---|---|
point | The input point. Must be a point data type with spatial reference system WGS84 (SRID=4326). |
timezoneId | Controls the output format. true (default): returns an IANA time zone name (for example, Asia/Shanghai). false: returns a GMT offset string (for example, Etc/GMT+8). |
timezonePrecision | The lookup precision. Valid only when timezoneId is true. 16 (default): ~500 m precision. 21: ~20 m precision. Use 21 for points near time zone boundaries where a 500 m error could return the wrong time zone. |
Return value
Returns a cstring containing the time zone string.
Background
Time zone boundary data comes from the Timezone Boundary Builder project.
Examples
Return an IANA time zone name (default behavior):
SELECT ST_TimeZone('SRID=4326;POINT(121 37)'::geometry);
-- Asia/Shanghai
SELECT ST_TimeZone('POINT(60 37)'::geography);
-- Asia/TehranReturn a GMT offset string:
SELECT ST_TimeZone('SRID=4326;POINT(121 37)'::geometry, false);
-- Etc/GMT+8Use higher precision for a point near a time zone boundary:
SELECT ST_TimeZone('SRID=4326;POINT(-121 37)'::geometry, true, 21);
-- America/Los_AngelesPass a longitude greater than 180°:
SELECT ST_TimeZone(('SRID=4326;POINT(400 37)'::geometry));
-- Europe/Istanbul