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

date_start (Optional): Date in YYYY-MM-DD format to specify a range, date_start will be used as a start date.

date_end (Optional): Date in YYYY-MM-DD format used to specify the end of a date range. If this is left empty and date_start is set it’ll default to the current day.

time_format (Optional): Format that all the times are displayed in. Default is a 12-hour clock but acceptable values include “24” for a 24-hour clock, “military” for military time, and “unix” for unix timestamps. Note that unix timestamps are only returned in UTC.

formatted (Optional): Set to 0 to receive times in ISO 8601 format (e.g., 2026-01-15T07:27:02+00:00) and day_length in seconds. Default is 1 which returns human-readable formatted times.

elevation (Optional): Controls elevation-adjusted sunrise/sunset times. By default the API auto-detects elevation from the location’s coordinates using terrain data. Set to “false” to disable and use sea level. You can also pass a specific elevation in meters (e.g., elevation=1609). Higher elevations result in earlier sunrises and later sunsets.

callback (Optional): Callback function name for JSONP response. Useful for cross-domain requests from older browsers. Example: callback=handleSunData will return handleSunData({…}) with content type application/javascript.

About

The free SunriseSunset.io API is perfect for displaying sunset and sunrise times in your applications or websites using JSON. Currently we serve millions of requests a month to developers and their apps.

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, sun position, moonrise, moonset, moon phase, moon illumination, elevation, UTC offset, and timezone. No login or authentication is required to use our free API.

The API automatically adjusts sunrise and sunset times based on the location’s elevation using terrain data. You can also query up to 365 days of sunrise, sunset, and moon data with one request using the date_start and date_end parameters.

Enjoy our free Sunset and Sunrise API? Donate

Example Requests

Standard request:
https://api.sunrisesunset.io/json?lat=38.907192&lng=-77.036873

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

Date range request:
https://api.sunrisesunset.io/json?lat=38.907192&lng=-77.036873&date_start=1990-05-01&date_end=1990-07-01

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

Return Unix epoch time:
https://api.sunrisesunset.io/json?lat=38.907192&lng=-77.036873&timezone=UTC&date=1990-05-22&time_format=unix

Example returned JSON data:

{
  "results": {
    "date": "2026-04-04",
    "sunrise": "6:48:29 AM",
    "sunset": "7:36:01 PM",
    "first_light": "5:16:33 AM",
    "last_light": "9:07:57 PM",
    "dawn": "6:21:29 AM",
    "dusk": "8:03:01 PM",
    "solar_noon": "1:12:15 PM",
    "golden_hour": "7:00:44 PM",
    "day_length": "12:47:32",
    "nautical_twilight_begin": "5:49:31 AM",
    "nautical_twilight_end": "8:34:59 PM",
    "timezone": "America/New_York",
    "utc_offset": -240,
    "sun_altitude": 56.81,
    "sun_azimuth": 180.33,
    "sunrise_azimuth": 82,
    "sunset_azimuth": 278.38,
    "moonrise": "9:38:28 PM",
    "moonset": "7:48:47 AM",
    "moon_illumination": 92.7,
    "moon_phase": "Waning Gibbous",
    "moon_phase_value": 0.59,
    "moon_always_up": false,
    "moon_always_down": false,
    "elevation": 26
  },
  "status": "OK",
  "tzid": "America/New_York"
}

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. You can also use a site like GPSCoordinates.io to find your current location’s coordinates.

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

Subscribe for API Updates

Name(Required)

Frequently Asked Questions

Is the Sunrise and Sunset API free to use?

Yes, the SunriseSunset.io API is completely free for both personal and commercial projects. We do not require an API key or a paid subscription to access our data. We only ask that you provide a backlink to our website (e.g., “Powered by SunriseSunset.io”) to help support the service and keep it free for the developer community.

Does the API support batch requests for date ranges?

Absolutely. Unlike many other solar APIs, you can query up to 365 days of data in a single request. By using the date_start and date_end parameters, you can retrieve a full year’s worth of sunrise, sunset, and golden hour times. This is ideal for building annual calendars or scheduling apps without making hundreds of individual API calls.

How accurate are the sunrise and sunset times provided?

Our API provides highly accurate solar calculations based on your specific latitude and longitude. We calculate various solar events including civil twilight (dawn/dusk) and nautical twilight (first/last light). For locations in extreme latitudes (like the North or South Poles) where the sun may not rise or set, our API returns a null value to ensure your application remains data-accurate. Currently we support terrain and elevation effects on sunrise and sunset times with elevation being returned in the API.

Can I get the API response in ISO 8601 or Unix format?

Yes. For developers who need to store data in databases or perform time-zone conversions, you can set the formatted=0 parameter to receive times in ISO 8601 format. Additionally, the time_format=unix parameter allows you to retrieve data as Unix timestamps (UTC), making it easy to integrate with various programming languages and frameworks.

Is an API key required to start making requests?

No, there is no registration or API key required. You can start integrating solar data into your website or app immediately by sending a GET request to our endpoint. This “no-friction” approach allows for rapid prototyping and deployment for developers working with JavaScript, Python, PHP, or any other language.


Changelog

  • Apr 4, 2026: Added moon data (moonrise, moonset, moon phase, moon illumination), sun position data (altitude and azimuth at solar noon, sunrise, and sunset), and automatic elevation-adjusted sunrise/sunset times using terrain data. Added elevation parameter to control elevation behavior.
  • Jan 14, 2026: Added JSONP callback support, formatted parameter for ISO 8601 output, nautical twilight times, and specific status codes (INVALID_REQUEST, INVALID_DATE, INVALID_TZID, UNKNOWN_ERROR).
  • Apr 13, 2025: Fixed a bug that caused issues with day light savings and selecting the wrong date.
  • Jul 30, 2024: Added the ability to change the output time format with time_format options. This is great for users who want 24-hour time, see acceptable variables in the documentation above.
  • Nov 29, 2023: Added the ability to do a date range with date_start and date_end. This allows you to get up to 1 year of sunset times at one time. Also added the date that’s being queried to the response of all SunriseSunset requests.
  • Oct 13, 2023: API response times increased again.
  • 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 Sunrise Sunset API Status Page