Day.js Hijri Plugin
A lightweight Day.js plugin for Hijri calendar conversion and formatting.
This plugin adds Hijri calendar (Based on Umm al-Qura calculations) support to Day.js, enabling developers to seamlessly convert and manipulate Hijri dates while leveraging Day.js's lightweight API.
Installation
NPM
npm install --save dayjs-hijriYARN
yarn add dayjs-hijriUsage
import dayjs from 'dayjs'
import dayjsHijri from 'dayjs-hijri'
dayjs.extend(dayjsHijri)Parse Date
- Parse Gregory date
const date = dayjs('2025-01-07T16:00:00.000Z'); - Parse hijri date that only gives you a dayjs object that has only Gregory date
const date = dayjs('1446-10-17', { hijri: true });
Changing calendar
If you want to all new instanses of dayjs use hijri calendar, you can set default calendar
dayjs.calendar('hijri') // hijri Calendar
// OR
dayjs.calendar('gregory') // Gregorian Calendaralso you can create a hijri date without changing default calendar
const date = dayjs()
const hijriDate = date.calendar('hijri')Multiple Locale
with combination of calendar and locale we have multi language for real
dayjs('2025-01-07').calendar('hijri').locale('en').format('DD MMMM YYYY') // '07 Rajab 1446'
dayjs('1446-07-07').calendar('gregory').locale('ar').format('DD MMMM YYYY') // '07 ینایر 2025'Live Demo
Try the plugin live on CodeSandbox: Open Demo.
License
MIT © 2025 M25D