Sunset and Sunrise Times API

Accurate Sunrise & Sunset Times for Developers

SunriseSunset.io offers a free API for retrieving sunrise and sunset times for a specific longitude and latitude.

Parameters

lat (Required): Latitude of the location in decimal degrees. Example: 38.907192
lng (Required): Longitude of the location in decimal degrees. Example: -77.036873
date (Optional): Date in YYYY-MM-DD format, you can also specify relative formats such as “today” and “tomorrow”. If not set it’ll default to today.
timezone (Optional): Set a timezone of the returned times (timezone list). By default the API will return the times in the location’s timezone. If SunriseSunset cannot validate a timezone it’ll fallback to the default which is the location’s timezone. Example: UTC

About

The SunriseSunset.io API is perfect for displaying sunset and sunrise times in your applications or websites. Requests are sent using GET parameters and returned data is in JSON format. Returned information includes sunrise, sunset, first light, last light, dawn, dusk, solar noon, golden hour, day length, UTC offset, and timezone displayed.

Enjoy the API? Donate

Example Requests

https://api.sunrisesunset.io/json?lat=38.907192&lng=-77.036873
https://api.sunrisesunset.io/json?lat=38.907192&lng=-77.036873&timezone=UTC&date=1990-05-22

Example returned JSON data:

{
	"results": {
		"sunrise": "5:49:47 AM",
		"sunset": "8:23:14 PM",
		"first_light": "3:57:44 AM",
		"last_light": "10:15:17 PM",
		"dawn": "5:18:56 AM",
		"dusk": "8:54:05 PM",
		"solar_noon": "1:06:31 PM",
		"golden_hour": "7:44:26 PM",
		"day_length": "14:33:26",
		"timezone": "America/New_York",
		"utc_offset": -240
	},
	"status": "OK"
}

If you plan on using our free API you must include a link to our site. For example “Powered by SunriseSunset.io“.

You’ll also notice API URLs for each location are listed at the bottom of location pages (example: NYC). This makes it easy to get an API call URL for a specific city or point of interest.

A location like the north pole won’t always have a sunrise/sunset time. If one of the sun events doesn’t exist in that location the API will return null instead of the time for the specific event.

Example Usage (Javascript)

Here’s a simple example of grabbing sunrise/sunset times for NYC using Javascript fetch.

// Coordinates for New York
const latitude = 40.71427
const longitude = -74.00597
const url = `https://api.sunrisesunset.io/json?lat=${latitude}&lng=${longitude}`

fetch(url)
  .then(response => response.json())
  .then(data => {
    console.log(data)
  })
  .catch(error => console.error('Error:', error))

View full example on CodePen

Changelog

  • May 26, 2023: Increased speed of API responses plus added “utc_offset” to responses.
  • April 16, 2023: Stability improvements when requesting a location without first/last light. Additionally fixed a CORS issue with cached requests.
  • June 21, 2022: Added first light and last light to returned information.
  • June 17 2022: Added link to API status page.
  • June 9, 2022: API Released.

SunriseSunset.io API Status Page