Sunset and sunrise times API

We offer a free API that provides sunset and sunrise times for a given latitude and longitude.

Please note that attribution is required if you use our API. Check "Usage limits and attribution" section below for more information.

API documentation

Ours is a very simple REST api, you only have to do a GET request to https://api.sunrise-sunset.org/json. No need to sign up or get an API Key.

Request parameters

Sample requests

These are three sample requests for getting sunset and sunrise information from our API for a given location:


https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400

https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&date=today

https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&date=2024-03-19
https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&formatted=0

Response

The API response include the times for the sun events in the given location. Data is formatted using JSON.

Note that unless you provide a tzid, all times are in UTC and summer time adjustments are not included in the returned data.

An example response:


    {
      "results":
      {
        "sunrise":"7:27:02 AM",
        "sunset":"5:05:55 PM",
        "solar_noon":"12:16:28 PM",
        "day_length":"9:38:53",
        "civil_twilight_begin":"6:58:14 AM",
        "civil_twilight_end":"5:34:43 PM",
        "nautical_twilight_begin":"6:25:47 AM",
        "nautical_twilight_end":"6:07:10 PM",
        "astronomical_twilight_begin":"5:54:14 AM",
        "astronomical_twilight_end":"6:38:43 PM"
      },
       "status":"OK",
       "tzid": "UTC"
    }
  

Response without date formatting:


    {
      "results":
      {
        "sunrise":"2015-05-21T05:05:35+00:00",
        "sunset":"2015-05-21T19:22:59+00:00",
        "solar_noon":"2015-05-21T12:14:17+00:00",
        "day_length":51444,
        "civil_twilight_begin":"2015-05-21T04:36:17+00:00",
        "civil_twilight_end":"2015-05-21T19:52:17+00:00",
        "nautical_twilight_begin":"2015-05-21T04:00:13+00:00",
        "nautical_twilight_end":"2015-05-21T20:28:21+00:00",
        "astronomical_twilight_begin":"2015-05-21T03:20:49+00:00",
        "astronomical_twilight_end":"2015-05-21T21:07:45+00:00"
      },
       "status":"OK",
       "tzid": "UTC"
    }
  

Consult our glossary of astronical definitions to understand each element of the response object.

Status codes

The "status" field within the API response object contains the status of the request. The "status" field may contain the following values:

How to use the API from an AJAX request?

Use the parameter callback to receive a JSONP response and avoid cross domain boundaries:

https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&callback=mycallback

Usage limits and attribution

The sunrise and sunset API can be used free of charge. You may not use this API in a manner that exceeds reasonable request volume, constitutes excessive or abusive usage. We require that you show attribution to us with a link to our site.

Announcements

Subscribe to our API newsletter to keep up to date with changes and announcements about the service:



💡 Got a cool idea? 🤦 Found any errors?

We're always improving this website!

If you have an idea of some content or information to include in this page or found an error, please let us know!

Changelog

Contact

Please contact us for all your API questions.

If you enjoy using our API please consider supporting the project by buying us a coffe!