TL;DR
The Sunrise and Sunset API calculates precise solar times for any GPS location on Earth. Pass latitude and longitude and get back sunrise, sunset, solar noon, civil twilight (dawn/dusk), nautical twilight, and astronomical twilight times for any given date. Uses the NOAA solar calculator algorithm. The response is lightweight JSON with all times in UTC. Completely free, no API key, no rate limits — essential for photography planning, astronomy, smart home automation, and outdoor activity apps.
Quick start: https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400
No API key needed — just make a request!
https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400
How to Use This API
1. Get Sun Times for Coordinates
https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400
Returns: sunrise, sunset, solar_noon, day_length, civil_twilight_begin, civil_twilight_end, nautical_twilight_begin, nautical_twilight_end, astronomical_twilight_begin, astronomical_twilight_end. All times UTC.
2. Specific Date
Add the date parameter (YYYY-MM-DD):
https://api.sunrise-sunset.org/json?lat=48.8566&lng=2.3522&date=2026-06-21
3. 24-Hour Format
Add formatted=0 for machine-readable ISO 8601 timestamps:
https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&formatted=0
4. JavaScript — Golden Hour Calculator
async function getGoldenHour(lat, lng) {
const resp = await fetch(
`https://api.sunrise-sunset.org/json?lat=${lat}&lng=${lng}&formatted=0`
);
const data = await resp.json();
const r = data.results;
console.log(`Location: ${lat}, ${lng}`);
console.log(`Sunrise: ${r.sunrise}`);
console.log(`Sunset: ${r.sunset}`);
console.log(`Day length: ${r.day_length}`);
console.log(`Golden hour starts: ${r.civil_twilight_begin}`);
console.log(`Golden hour ends: ${r.civil_twilight_end}`);
}
getGoldenHour(51.5074, -0.1278); // London
5. Python — Compare Day Lengths
import requests
from datetime import datetime
cities = [
('Reykjavik', 64.1466, -21.9426),
('London', 51.5074, -0.1278),
('Singapore', 1.3521, 103.8198),
]
for name, lat, lng in cities:
resp = requests.get(
'https://api.sunrise-sunset.org/json',
params={'lat': lat, 'lng': lng, 'formatted': 0}
)
r = resp.json()['results']
sr = r['sunrise'][11:16]
ss = r['sunset'][11:16]
print(f"{name}: Sunrise {sr}, Sunset {ss} ({r['day_length']}s)")
Frequently Asked Questions
- What times does the API return?
- Sunrise, sunset, solar noon, civil twilight begin/end, nautical twilight begin/end, astronomical twilight begin/end, and day length. All times are in UTC by default.
- What's the difference between twilight types?
- Civil twilight (sun 6° below horizon — best for photography), nautical twilight (12° — horizon distinguishable), astronomical twilight (18° — sky fully dark). Each has a start and end time.
- Do I need an API key?
- No. The API is completely free with no authentication required.
- How accurate are the calculations?
- The API uses the NOAA solar calculator which is accurate to within 1-2 minutes for any location on Earth. Accuracy depends on the quality of the input coordinates.
- What format does the response use?
- JSON. By default times are formatted as HH:MM:SS AM/PM. Use
formatted=0for ISO 8601 UTC timestamps. - Can I get data for past or future dates?
- Yes, the
dateparameter accepts any date in YYYY-MM-DD format. Past, present, and future dates all work.
API Details
- API URL
https://api.sunrise-sunset.org/json- Documentation
- sunrise-sunset.org/api
- Category
- Science
- Authentication
- Not Required
- Geographic Coverage
- Global — any GPS coordinate
What You Can Build
- Photography planner that shows golden hour and blue hour times
- Smart home system that triggers window blinds at sunset
- Gardening app that schedules planting based on daylight hours
- Travel itinerary tool showing local sunrise/sunset for destinations
- Running/cycling app that plans workouts around daylight availability