Sunset time calculator
At the equator, with the Sun's declination at 23.44°, the Sun sets at 6 p.m. solar time, a 90° hour angle after noon. Enter the latitude, the declination and your clock offset to get the local sunset as a decimal hour. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Latitude
- 0
- Declination
- 23.44
- Tz offset
- 0
- Hour angle deg
- 90
- Sunset solar hours
- 18
- Sunset hours
- 18
Sunset time is a closed trigonometric function of three quantities: the observer's geographic latitude, the Sun's declination on that date, and the hours that the local clock sits ahead of apparent solar time. This sunset calculator evaluates the geometric identity cos ω equals minus tan φ times tan δ, converts the sunset hour angle ω into decimal hours after solar noon, then adds the time-zone offset to produce a local clock time in decimal hours. Polar night, where the Sun never rises, is rejected for the same reason: there is no sunset to report.
What the sunset hour angle is and how it becomes a local clock hour
Apparent solar noon is the instant when the local hour angle is zero: the Sun stands on the observer's meridian and shadows point true north or south. Sunset sits after that noon at plus a single angle ω, the sunset hour angle. The same cosine can be written without tangents as minus sin φ sin δ over cos φ cos δ, which stays finite at the poles where tan φ diverges.
The Earth turns fifteen degrees of hour angle every civil hour, so the solar-time sunset is twelve plus ω in degrees divided by fifteen, or equivalently twelve plus twelve ω over π when ω is in radians. Decimal hours are the contract: 18.5 means half past six in the evening, 19.25 means 19:15. This page evaluates that identity only.
It does not convert a calendar date into declination, it does not add the conventional minus zero point eight three three degrees that civil sunset tables use for refraction plus the solar semi-diameter, and it does not fold in longitude or the equation of time. Those corrections answer different search intents. Here the question is strictly geometric: given φ, δ, and a clock offset from apparent solar time, at what decimal hour does the Sun meet the true horizon, or does it never set at all.
What you enter, midnight sun and what you get
When |tan φ tan δ| exceeds one the Sun either never sets or never rises. Midnight sun — the product of the tangents greater than one with φ and δ the same sign — is rejected with a message that the Sun never sets at this latitude and declination. Polar night — opposite signs past the same threshold — is rejected because there is no sunset hour when the disk never clears the horizon.
Poles and a declination of plus or minus ninety degrees use the sign of sin φ sin δ for the same test, because the tangent form diverges. At the equator tan φ vanishes, so ω is always a right angle and solar sunset is 18.0 for every declination; a zero offset leaves the local result at 18 as well. Pair the decimal hour with your own formatter if you need HH:MM on a label.
Where a sunset time calculator earns its keep
Architecture and daylighting studios use a sunset time calculator to place the geometric dusk hour on a given latitude and design-day declination without opening an astronomy almanac. Field biologists and agronomists who already know δ from a day-of-year formula need the matching clock hour so feeding, irrigation, or observation windows sit after true dusk rather than after an arbitrary civil table.
Outdoor event planners, photographers, and film units convert a site latitude plus a chosen declination into a decimal hour they can drop into a call sheet, then add the local offset so the number matches the clocks on set. Prefer this page when the search intent is sunset time itself — the local decimal hour from φ, δ, and a timezone offset — rather than daylight duration, sunrise, civil twilight, or a calendar date converted through an ephemeris. Those related tools answer different queries and should not cannibalize this landing.
Failed validation, including midnight sun, does not consume balance. The calculator will not invent a sunset on a polar day; if your site is inside the midnight-sun belt, treat the error as the physical answer and switch to a day-length or solar-altitude tool for the rest of the story.
What you can do with it
Daylighting and architecture studios
Place geometric dusk on a design-day declination and site latitude, then shift by the local clock offset for shading and facade studies.
Field work and outdoor call sheets
Turn a known latitude and solar declination into a decimal sunset hour for observation windows, photography, and event schedules.
Energy and lighting control scripts
Feed the same hour angle already used for day length into relays and inverter schedules that need the clock of sunset, not just the duration.
FAQ
How is local sunset time computed from latitude and declination?
The geometric hour angle satisfies cos ω = −tan φ tan δ. Solar sunset is 12 + ω°/15 decimal hours.
What happens if the Sun never sets?
Polar night is rejected for the same reason: there is no sunset when the disk never rises.
What does a decimal sunset hour mean?
Values wrap onto [0, 24) when a large timezone offset pushes solar evening onto the next civil morning.
Why doesn't the result match the sunset time in my weather app?
This is the geometric sunset, when the centre of the Sun meets the true horizon. Published tables also correct for refraction and the size of the solar disk, your longitude and the equation of time, which this calculator leaves out.
Where do I get the Sun's declination for a given date?
You have to supply it: the calculator does not turn a calendar date into a declination. Over the year it stays within about plus or minus 23.44 degrees, the typical range for the Earth.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/phys/sunset \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"lat":40,"declination":23.44,"tz_offset":0}'const res = await fetch("https://api.kit.forhosting.com/phys/sunset", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"lat": 40,
"declination": 23.44,
"tz_offset": 0
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/phys/sunset",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"lat": 40,
"declination": 23.44,
"tz_offset": 0
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/phys/sunset", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"lat":40,"declination":23.44,"tz_offset":0}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"lat":40,"declination":23.44,"tz_offset":0}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/phys/sunset", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"lat": 40,
"declination": 23.44,
"tz_offset": 0
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "phys.sunset",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
When the product of the tangents exceeds one, the Sun never sets — midnight sun — and the task fails with invalid_input instead of inventing a clock hour.
What the sunset hour angle is and how it becomes a local clock hour
On a spherical Earth with a true geometric horizon — the solar-disk centre, no atmospheric refraction — the Sun's altitude is zero precisely when the cosine of ω equals minus the product of the tangent of latitude and the tangent of declination: cos ω = −tan φ tan δ. Adding the time-zone offset then shifts that solar hour onto the local clock: sunset hours equals wrap-to-twenty-four of twelve plus ω over fifteen plus tz_offset.
Input contract, midnight sun, and the response shape
POST a JSON body with three required finite numbers. lat is geographic latitude in decimal degrees, positive north and negative south, in the closed interval from minus ninety to plus ninety; the alias latitude is accepted. declination is the Sun's celestial latitude in decimal degrees, in the same interval; aliases decl, delta, solar_declination, and dec are accepted so a notebook that already labels the column δ does not need a rename. tz_offset is hours added to apparent solar time to obtain the local clock, in the closed interval from minus fourteen to plus fourteen so every civil UTC offset, including fractional zones such as 5.5, fits; aliases timezone_offset, utc_offset, offset, and tz are accepted. A missing field, an empty string, a non-numeric token, NaN, or Infinity fails with invalid_input naming the field, and that failure is not billed. On success the body echoes lat, declination, and tz_offset after stable twelve-decimal rounding; returns hour_angle_deg as ω in degrees; returns sunset_solar_hours as the unwrapped solar-time sunset; and returns sunset_hours as the primary local clock time wrapped onto [0, 24). The formula string restates t = 12 + arccos(−tan φ tan δ)°/15 + tz_offset. A successful item is billed at the published $0.002.
Where a sunset time calculator earns its keep
Energy models that already compute day length from the same hour angle still need the clock of sunset when they schedule inverter curtailment or street-lighting relays; this endpoint returns that hour instead of the duration. Because each successful call is a single analytic item priced at $0.002, batch scripts can sweep a latitude band or a year of declination values without a subscription or a model cost. Keep requests small, pin the rounded sunset_hours in tests, and you get a reproducible textbook baseline for homework, LMS plugins, and edge workers without standing up an astronomy library.
Technical questions
Does tz_offset include longitude or the equation of time?
No. tz_offset is hours added to apparent solar time. Longitude, the equation of time, and civil refraction (the usual −0.833°) are out of scope for this three-input geometric contract.
What does the sunset time calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input, including midnight sun, is not billed.