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 http://api.sunrise-sunset.org/json.

Parameters

Sample requests

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


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

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

http://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&date=2016-07-24

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

Response

The result data is formatted using JSON. An example:

NOTE: All times are in UTC and summer time adjustments are not included in the returned data.


    {
      "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"
    }
  

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"
    }
  

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:

http://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.

Changelog

Contact

Please contact us for all your API questions.