Is modern browser fast and small with zero dependency native JavaScript datetime converting and formatting from Shamsi/Jalali/Persian to Gregory and vice versa.
The API using modern browser Intl.DateTimeFormat object for date and time formatting.
Quick Info:
Shamsi/Jalali/Persian or Solar Hijri Calendar currently using in Afghanistan, Iran and Tajikistan you can find more info Here the API converting and formatting datetime to gregory and vice versa.
in Browser: در بروزر
You can Download and link to file.
<script src="path/to/chaj.js"></script>npm install chajdate
- Currently, there is only one public method:
Chaj.format()
The method taking tow paramters date as string in ISO 8601 format, and second param as object with all available and valid properties of Intl.DateTimeFormat - Options and return converted/formatted date as string/array
By default Chaj.format() with zero param return current local date & time.
const Chaj = require('chajdate');
// with no parameters.
Chaj.format() // current date 0000/00/00
// convert/format gregory to shamsi/jalali/persian
Chaj.format('2022-10-25') // 1401/8/3
// convert/format shamsi/jalali/persian to gregory
Chaj.format('1401-8-25', {shamsi: true}) // 11/16/2022
// Customize the date by adding more options
Chaj.format(null, {dateStyle: 'full'}) // current date
Chaj.format('2022-10-25', {dateStyle: 'full'}) // 1401 عقرب 3, سهشنبه
Chaj.format('1401-10-02', {shamsi: true, dateStyle: 'full'}) // Friday, December 23, 2022-
First Param Date as
stringin ISO 8601 format a space instead of the "T" is allowed.Chaj.format('2022-10-25T12:00:00.000Z')` - `Chaj.format('2022-10-25 14:25')
-
Second Param as
object {}you can pass all Intl.DateTimeFormat - Options at once.Chaj.format('2022-10-25', { dateStyle: 'full', locale: 'en-US', timeZone: 'Asia/Kabul', calendar: 'persian'} )
-
Converting shamsi/jalali/persian date to gregory add
shamsiasbooleandefault isfalse.Chaj.format('1401-8-25', { shamsi: true, dateStyle: 'full', locale: 'en-US', timeZone: 'Asia/Kabul', calendar: 'persian'} )
-
By default it converting/formatting date with local datetime. you can add
utckey to option withbooleanvalue default is false for converting/formatting date and time to UTC.Chaj.format('1401-8-25', { shamsi: true, utc: true, dateStyle: 'full', locale: 'en-US', timeZone: 'Asia/Kabul', calendar: 'persian'} )
By default it return as string you can add toArray as boolean for returning value as array of objects.
- Date as
stringcurrent local date & time. - Options as
objecttimeZone: 'Asia/Kabul', calendar: 'persian', locale: 'fa-AF-u-nu-latn', utc: false, shamsi: false, toArray: false
you can find more formatting information about Intl.DateTimeFormat - Options , Thanks to MDN documentation Here
Browser/Nodejs Support
| Chrome | Firefox | Safari | Opera | Edge | Nodejs |
|---|---|---|---|---|---|
| Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
TODO: add more public methods.