- Notifications
You must be signed in to change notification settings - Fork27
A Jalali to Gregorian converter in Javascript with support of formatting output
License
arashm/JDate
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Jalali to Gregorian converter in JavaScript with support of formatting output
Install via NPM/Yarn:
npm install jalali-date
You could grab the latest version fromlib
directory and use it:
<head><scriptsrc="jdate.js"type="text/javascript"charset="utf-8"></script><scriptsrc="jdate.min.js"type="text/javascript"charset="utf-8"></script></head>
The full-version is useful for debugging. You may want to use minified version in production as it is smaller.
For initializingJDate
you may either pass an array of Jalali date to it or aDate
object. If no parameter is passed, the default is today:
constJDate=require('jalali-date');constjdate=newJDate;// => default to todayconstjdate2=newJDate(1393,10,11);constjdate3=newJDate([1393,10,11]);constjdate4=newJDate(newDate(2014,1,3));
jdate.date//=> [1393, 5, 13] An Array of Jalali Datejdate._d// => Gregorian Date Object// Gettersjdate.getFullYear()// => 1393jdate.getMonth()// => 5jdate.getDate()// => 13jdate.getDay()// => 1// Settersjdate.setFullYear(1394)jdate.setMonth(6)jdate.setDate(12)// Formatting outputjdate.format('dddd DD MMMM YYYY')// => پنجشنبه 12 شهریور 1394// Static functionsJDate.isLeapYear(1393)// => falseJDate.daysInMonth(1393,5)// => 31JDate.toGregorian(1393,12,11)// => Gregorian Date objectJDate.toJalali(newDate)// => JDate object
Useformat()
and following conversion identifiers as follows:
date.format('dddd DD MMMM YYYY')//=> دوشنبه 6 امرداد 1393
The conversion identifiers are as follows:
Identifier | Description | Example |
---|---|---|
YYY orYYYY | Full Year (4 digits) | 1393 |
YY | Year (2 digits) | 93 |
M | Month in number | returns5 forامرداد |
MM | Month in number | returns05 forامرداد |
MMM orMMMM | Month in string | امرداد |
D | Day in number | 26 |
DD | Day in number | 06 |
d ordd | Abbreviation of day name in string | ۱ش (for یکشنبه) |
ddd ordddd | Full day name in string | یکشنبه |
Report bugs and suggest feature inissue tracker. Feel free toFork
and sendPull Requests
.
About
A Jalali to Gregorian converter in Javascript with support of formatting output