Persian (Jalali, Khorshidi) Plugin for Day.js
npm install jalalidayJalaliday is collection of Date utilities for Persian (Jalali, Khorshidi) and Gregorian (UTC) calendars.
- jalaliday/dayjs is Persian (Jalali, Khorshidi) Plugin for Day.js, Jalaliday add multi-calendar functionality to Day.js core regardless for of locale, so we can have Gregorian calendar is Persian locale of Jalali calendar in English locale
Unlike moment and becuase of immutablity of dayjs, there is no need for formats like jYYYY or jMM, in Jalaliday all formats are same and standard
- jalaliday/intl is collection of utilities built on top of Intl.DateTimeFormat API.
npm install --save jalaliday
`
YARN
`
yarn add jalaliday
`Dayjs Usage
`javascript
import dayjs from 'dayjs'
import jalaliday from 'jalaliday/dayjs'dayjs.extend(jalaliday)
`$3
If you want to all new instanses of dayjs use jalali calendar, you can set default calendar
`javascript
dayjs.calendar('jalali') // Jalali Calendar
// OR
dayjs.calendar('gregory') // Gregorian Calendar
`
also you can create a jalali date without changing default calendar
`javascript
const date = dayjs()
const jalaliDate = date.calendar('jalali')
`$3
- Parse Gregory date
`js
const date = dayjs('2018-04-04T16:00:00.000Z');
`
- Parse Jalali date
`js
const date = dayjs('1398-10-17', { jalali: true });
`$3
with combination of calendar and locale we have multi language for real
`javascript
dayjs().calendar('jalali').locale('en').format('DD MMMM YYYY') // '13 Shahrivar 1397'
dayjs().calendar('gregory').locale('fa').format('DD MMMM YYYY') // '04 سپتامبر 2018'
`$3
All Api operations of Jalaliday is same as Dayjs itself but calendar based, for more information checkout Dayjs API
Dayjs API in a glance
- API Reference
- Parsing
- Constructor
dayjs(existing?: string | number | Date | Dayjs)
- ISO 8601 string
- Unix Timestamp (milliseconds since the Unix Epoch - Jan 1 1970, 12AM UTC)
- Native Javascript Date object
- Clone .clone() | dayjs(original: Dayjs)
- Validation .isValid()
- Get and Set
- Year .year()
- Month .month()
- Day of the Month .date()
- Day of the Week .day()
- Hour .hour()
- Minute .minute()
- Second .second()
- Millisecond .millisecond()
- Set .set(unit: string, value: number)
- Manipulating
- Add .add(value: number, unit: string)
- Subtract .subtract(value: number, unit: string)
- Start of Time .startOf(unit: string)
- End of Time .endOf(unit: string)
- Displaying
- Format .format(stringWithTokens: string)
- List of all available formats
- Difference .diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)
- Unix Timestamp (milliseconds) .valueOf()
- Unix Timestamp (seconds) .unix()
- Days in the Month .daysInMonth()
- As Javascript Date .toDate()
- As Array .toArray()
- As JSON .toJSON()
- As ISO 8601 String .toISOString()
- As Object .toObject()
- As String .toString()
- Query
- Is Before .isBefore(compared: Dayjs)
- Is Same .isSame(compared: Dayjs)
- Is After .isAfter(compared: Dayjs)
- Is a Dayjs .isDayjs()
- Plugin APIs
- RelativeTime
- IsLeapYear
- WeekOfYear
- IsBetweenIntl Usage
`javascript
import { formatDate } from 'jalaliday/intl'const date = new Date('2025-06-22T10:20:30.000Z')
formatDate(date) // '1404/04/01'
formatDate(date, 'YYYY/MM/DD') // '1404/04/01'
formatDate(date, 'YYYY/MM/DD HH:mm:ss') // '1404/04/01 13:50:30'
formatDate(date, 'YYYY/MM/DD HH:mm:ss') // '1404/04/01 13:50:30'
``