Adhan JS is a well tested and well documented library for calculating Islamic prayer times in JavaScript using Node or a web browser.
All astronomical calculations are high precision equations directly from the book “Astronomical Algorithms” by Jean Meeus. This book is recommended by the Astronomical Applications Department of the U.S. Naval Observatory and the Earth System Research Laboratory of the National Oceanic and Atmospheric Administration.
Implementations of Adhan in other languages can be found in the parent repo Adhan.
- 📦 Dual Package Support: Native distribution for both modern ES Modules (
import) and legacy CommonJS (require). - 🚀 Environment Agnostic: Runs flawlessly across Node.js, modern browsers, Bun, Deno, and frameworks like Next.js or Vite.
- ⛑️ Type Safe: Ships with native TypeScript declarations included out of the box.
- 🎯 High Precision: Implements strict, rigorous astronomical algorithms for pinpoint accuracy.
Adhan was designed to work seamlessly in both browser and server environments.
We provide both ESM and UMD bundles for native use in the browser via CDN.
<script type="module">
import {
Coordinates,
CalculationMethod,
PrayerTimes,
} from 'https://unpkg.com/adhan/lib/bundles/adhan.esm.js';
const coordinates = new Coordinates(35.789751, -78.691249);
const params = CalculationMethod.NorthAmerica();
const prayerTimes = new PrayerTimes(coordinates, new Date(), params);
console.log(prayerTimes.fajr);
</script><script src="https://unpkg.com/adhan/lib/bundles/adhan.umd.min.js"></script>
<script>
const coordinates = new adhan.Coordinates(35.789751, -78.691249);
const params = adhan.CalculationMethod.NorthAmerica();
const prayerTimes = new adhan.PrayerTimes(coordinates, new Date(), params);
</script>Install the package via your preferred package manager.
npm install adhan
import { Coordinates, CalculationMethod, PrayerTimes } from 'adhan';
const coordinates = new Coordinates(35.789751, -78.691249);
const params = CalculationMethod.MoonsightingCommittee();
const prayerTimes = new PrayerTimes(coordinates, new Date(), params);
console.log(prayerTimes.fajr);const adhan = require('adhan');
const coordinates = new adhan.Coordinates(35.789751, -78.691249);
const params = adhan.CalculationMethod.MoonsightingCommittee();
const prayerTimes = new adhan.PrayerTimes(coordinates, new Date(), params);
console.log(prayerTimes.fajr);To get prayer times initialize a new PrayerTimes object passing in coordinates,
date, and calculation parameters.
const prayerTimes = new PrayerTimes(coordinates, date, params);
if (prayerTimes.isValid) {
// prayerTimes.fajr, .sunrise, .dhuhr, .asr, .maghrib, .isha are valid
}Create a Coordinates object with the latitude and longitude for the location
you want prayer times for.
const coordinates = new Coordinates(35.78056, -78.6389);You can also pass in the location's UTC offset in hours. Without it, certain places near the international date line (South Pacific Islands) may get either the previous or next day's times instead.
const coordinates = new Coordinates(-21.1368, -175.2011, 13); // Nuku'alofaThe latitude must be within ±90°, both values must be finite numbers, and the
offset, if given, must be between -12 and +14. If they aren't, or if the date is
invalid, every prayer time field is set to an invalid Date (see
Polar circle locations for how to check
prayerTimes.isValid).
The date parameter passed in should be an instance of the JavaScript Date object. The year, month, and day values need to be populated. All other values will be ignored. The year, month and day values should be for the date that you want prayer times for. These date values are expected to be for the Gregorian calendar.
const date = new Date(); // current dateOr, for a specific date:
const date = new Date(2026, 0, 1); // specific dateThe rest of the needed information is contained within the CalculationParameters object.
Calculation Parameters & Methods Guide
If the location is above its horizon, such as a hill or tower overlooking the sea, see Elevation for adjusting sunrise and sunset.
The PrayerTimes object outputs raw JavaScript Date instances initialized to absolute UTC values.
Never assume the user's local device timezone matches the calculation coordinates. Always format prayer times with a specific Time Zone Identifier (e.g., Europe/London or America/New_York) to ensure the times display correctly and match with local daylight savings time (DST) adjustments.
We highly recommend utilizing the modern, native Temporal API (with a fallback polyfill if your target environment requires it):
Temporal.Instant.fromEpochMilliseconds(prayerTimes.fajr)
.toZonedDateTimeISO('America/New_York')
.toLocaleString('en-US', { hour: 'numeric', minute: '2-digit' });Near the polar circles (latitudes beyond ±66.56°) the sun may not rise or
set, or may not reach the angle required for a given prayer, on certain days
of the year. By default, the polarCircleResolution calculation parameter is
set to AqrabBalad, which automatically substitutes the closest latitude
(at the same longitude) for which prayer times can be computed, so this is
handled for you in almost every case.
It's still possible, though rare, for a substitute to not be found (or if
you've set polarCircleResolution to Unresolved yourself), in which case
PrayerTimes cannot compute that day's times and every prayer time field is
set to an invalid Date. Check prayerTimes.isValid before using the times:
const prayerTimes = new PrayerTimes(coordinates, date, params);
if (prayerTimes.isValid) {
// prayerTimes.fajr, .sunrise, .dhuhr, .asr, .maghrib, .isha are valid
} else {
// Prayer times could not be determined for this date/location.
}See polarCircleResolution for the other available
resolution strategies.
The PrayerTimes object has functions for getting the current prayer and the next prayer. You can also get the time for a specified prayer, making it easier to dynamically show countdowns until the next prayer.
var prayerTimes = new PrayerTimes(coordinates, date, params);
var current = prayerTimes.currentPrayer();
var next = prayerTimes.nextPrayer();
var nextPrayerTime = prayerTimes.timeForPrayer(next);The Adhan library can also calulate Sunnah times. Given an instance of PrayerTimes, you can get a SunnahTimes object with the times for Qiyam.
var sunnahTimes = new SunnahTimes(prayerTimes);
var middleOfTheNight = Temporal.Instant.fromEpochMilliseconds(
sunnahTimes.middleOfTheNight,
)
.toZonedDateTimeISO('America/New_York')
.toLocaleString('en-US', { hour: 'numeric', minute: '2-digit' });
var lastThirdOfTheNight = Temporal.Instant.fromEpochMilliseconds(
sunnahTimes.lastThirdOfTheNight,
)
.toZonedDateTimeISO('America/New_York')
.toLocaleString('en-US', { hour: 'numeric', minute: '2-digit' });SunnahTimes internally computes a second PrayerTimes for the following
day (using the same coordinates and calculation parameters) to determine the
length of the night. That computation can fail independently of the
PrayerTimes you passed in - near the polar circle, today's times may be
valid while tomorrow's aren't (or vice versa) - so check sunnahTimes.isValid
before using these times, even if prayerTimes.isValid was already true:
const sunnahTimes = new SunnahTimes(prayerTimes);
if (sunnahTimes.isValid) {
// sunnahTimes.middleOfTheNight, .lastThirdOfTheNight are valid
}Get the direction, in degrees from North, of the Qibla from a given set of coordinates.
var coordinates = new Coordinates(35.78056, -78.6389);
var qiblaDirection = Qibla(coordinates);See example.html for a full browser based example.
Migrating from version 3.x? Read the migration guide
Adhan is made publicly available to provide a well tested and well documented library for Islamic prayer times to all developers. We accept feature contributions provided that they are properly documented and include the appropriate unit tests. We are also looking for contributions in the form of unit tests of of prayer times for different locations, we do ask that the source of the comparison values be properly documented.
Note: Commit messages should follow the commit message convention so that changelogs can be automatically generated. Commit messages will be automatically validated upon commit. If you are not familiar with the commit message convention, you should use npm run commit instead of git commit, which provides an interactive CLI for generating proper commit messages.
Adhan is available under the MIT license. See the LICENSE file for more info.