Skip to content
Endpoint reference ยท v1

Sunrise & Sunset API

Calculate sunrise, sunset, twilight, solar noon and day length from coordinates.

GET/api/v1/sun

What It Does

Calculate sunrise, sunset, twilight, solar noon and day length from coordinates.

HTTP method
GET
Authentication
Public read-only; Bearer keys supported
Version
v1

Parameters

NameTypeRequiredDescription
citystringNoCity lookup alternative to coordinates.
Example: Karachi
latitudenumberNoLatitude, -90 to 90.
Example: 24.86
longitudenumberNoLongitude, -180 to 180.
Example: 67.01
datedateNoLocal calendar date. Defaults to today in the resolved timezone.
Example: 2026-09-09
timezonestringNoIANA timezone for local output.
Example: Asia/Karachi

Request Examples

cURL
curl -s 'https://worldclock.to/api/v1/sun?city=Karachi&latitude=24.86&longitude=67.01&date=2026-09-09&timezone=Asia/Karachi'
JavaScript
const response = await fetch("https:\/\/worldclock.to\/api\/v1\/sun?city=Karachi&latitude=24.86&longitude=67.01&date=2026-09-09&timezone=Asia\/Karachi");
const result = await response.json();
console.log(result.data);
PHP
$response = wp_remote_get('https://worldclock.to/api/v1/sun?city=Karachi&latitude=24.86&longitude=67.01&date=2026-09-09&timezone=Asia/Karachi');
 = json_decode(wp_remote_retrieve_body(), true);
Python
import requests

response = requests.get("https:\/\/worldclock.to\/api\/v1\/sun?city=Karachi&latitude=24.86&longitude=67.01&date=2026-09-09&timezone=Asia\/Karachi")
response.raise_for_status()
print(response.json()["data"])

Example Response

The values below illustrate the response shape. Live current-time fields are generated dynamically by the endpoint.

JSON
{
    "success": true,
    "data": {
        "date": "2026-09-09",
        "timezone": "Asia/Karachi",
        "latitude": 24.8599999999999994315658113919198513031005859375,
        "longitude": 67.0100000000000051159076974727213382720947265625,
        "sunrise": "2026-09-09T06:16:04+05:00",
        "sunset": "2026-09-09T18:43:31+05:00",
        "solar_noon": "2026-09-09T12:29:47+05:00",
        "civil_dawn": "2026-09-09T05:53:27+05:00",
        "civil_dusk": "2026-09-09T19:06:08+05:00",
        "day_length_seconds": 44847,
        "polar_day": false,
        "polar_night": false
    },
    "meta": {
        "version": "v1",
        "timezone": "Asia/Karachi",
        "timestamp": 1788946200
    }
}

Response Properties

Every successful response contains success: true, endpoint-specific data, and a meta object. The table below documents the public fields for this endpoint.

PropertyMeaning
successBoolean indicating whether the request completed successfully.
meta.versionPublished API response version.
meta.timestampUnix timestamp for the API response instant.
meta.timezoneTimezone context used by the response.
meta.rate_limitPer-client fair-use limit and remaining-request information on public transports.
data.dateLocal calendar date used for calculations.
data.timezoneTimezone used to format returned events.
data.latitudeCalculation latitude.
data.longitudeCalculation longitude.
data.sunriseSunrise as a timezone-aware ISO 8601 datetime, or null in polar conditions.
data.sunsetSunset as a timezone-aware ISO 8601 datetime, or null.
data.solar_noonApproximate local solar noon.
data.civil_dawnStart of civil twilight.
data.civil_duskEnd of civil twilight.
data.nautical_dawnStart of nautical twilight when calculable.
data.nautical_duskEnd of nautical twilight when calculable.
data.astronomical_dawnStart of astronomical twilight when calculable.
data.astronomical_duskEnd of astronomical twilight when calculable.
data.day_length_secondsSunrise-to-sunset duration in seconds when calculable.
data.polar_dayTrue when the sun does not set on the requested date at high latitude.
data.polar_nightTrue when the sun does not rise on the requested date at high latitude.
data.cityResolved city when city lookup is used.
data.countryResolved country when city lookup is used.

Errors use success: false with a stable machine-readable error code and a safe human-readable message.

Errors & HTTP Status Codes

  • 400 โ€” invalid or missing parameter.
  • 401 โ€” API key required or invalid when key-only access is enabled.
  • 404 โ€” unknown city, country or endpoint.
  • 429 โ€” configured rate limit reached.
  • 503 โ€” API disabled or maintenance mode.

Rate Limits & Caching

Current fair-use configuration is 60 requests per minute and 5000 requests per day. Cache stable directory/calculation responses where appropriate; treat current-time output as point-in-time data.

Related Endpoints