HijriNow is a JavaScript library that provides functionality for working with the Hijri calendar. This library allows you to convert dates between the Gregorian and Hijri calendars, retrieve information about the current date in the Hijri calendar, and more.
To use HijriNow in your project, you can include it via a CDN or install it using npm:
<script src="https://cdn.jsdelivr.net/npm/hijri-now/hijriNow.min.js"></script>
npm i hijri-now
- Description: Retrieves the current date in the Hijri calendar.
Usage:
const today = HijriNow.today();
console.log(today); // Output: "9/10/1445 هجري" (depending on the current date)
- Description: Retrieves the current month in the Hijri calendar.
Usage:
const month = HijriNow.month();
console.log(month); // Output: "10" (depending on the current date)
- Description: Retrieves the current year in the Hijri calendar.
Usage:
const year = HijriNow.year();
console.log(year); // Output: "1445" (depending on the current date)
- Description: Retrieves the current day in the Hijri calendar.
Usage:
const day = HijriNow.day();
console.log(day); // Output: "9" (depending on the current date)
- Description: Retrieves the name of the current month in the Hijri calendar.
Usage:
HijriNow.getMonthName()
.then(monthName => {
console.log(monthName); // Output: "شوال" (depending on the current date)
})
.catch(error => {
console.error(error);
});
- Description: Retrieves the name of the current day.
Usage:
HijriNow.getDayName()
.then(dayName => {
console.log(dayName); // Output: "الخميس" (depending on the current date)
})
.catch(error => {
console.error(error);
});
- Description: Retrieves congratulations message if today is a special occasion like Eid.
Usage:
HijriNow.CongratsNow()
.then(congratsMessage => {
console.log(congratsMessage); // Output: "عيد مبارك علينا وعليكم" if today is eid (depending on the current date)
})
.catch(error => {
console.error(error);
});
- Description: Adds a specified number of days to a given Hijri date.
-
Parameters:
-
dateString
: A string representing the Hijri date in the format "day/month/year". -
days
: The number of days to add.
-
Usage:
const newDate = HijriNow.addHijriDays("9/10/1445", 10);
console.log(newDate); // Output: "19/10/1445" (depending on the input date and days)
- Description: Checks if today is Eid in the Hijri calendar.
Usage:
HijriNow.isTodayEid()
.then(isEid => {
console.log(isEid); // Output: true or false (depending on the current date)
})
.catch(error => {
console.error(error);
});
- Description: Retrieves the current date in text format in the Hijri calendar.
Usage:
HijriNow.todayInText()
.then(dateText => {
console.log(dateText); // Output: "التاسع من شوال سنة 1446 هجري" (depending on the current date)
})
.catch(error => {
console.error(error);
});
- Description: Converts a Hijri date to Gregorian.
-
Parameters:
-
dateString
: A string representing the Hijri date in the format "day/month/year". -
splitter
: (Optional) The character used to split the date components.
-
Usage:
const gregorianDate = HijriNow.toGregorian("9/10/1445");
console.log(gregorianDate); // Output: "18/04/2024" (depending on the input date)
- Description: Converts a Gregorian date to Hijri.
-
Parameters:
-
dateString
: A string representing the Gregorian date in the format "day/month/year". -
splitter
: (Optional) The character used to split the date components.
-
Usage:
const hijriDate = HijriNow.toHijri("18/04/2024");
console.log(hijriDate); // Output: "9/10/1445" (depending on the input date)
The current language is Arabic. You can set it to English using this code:
HijriNow.currentLanguage = 'en'
Once included in your project, you can start using the HijriNow library in your JavaScript code as demonstrated in the feature descriptions above.
HijriNow relies on the user's system date and time settings to determine the current date in the Hijri calendar. Ensure that the user's system date and time settings are correctly configured for accurate results.