项目作者: arashm

项目描述 :
A Jalali to Gregorian converter in Javascript with support of formatting output
高级语言: JavaScript
项目地址: git://github.com/arashm/JDate.git
创建时间: 2014-08-02T19:04:23Z
项目社区:https://github.com/arashm/JDate

开源协议:MIT License

下载


JDate

Build Status
NPM Version
NPM License

A Jalali to Gregorian converter in JavaScript with support of formatting output

Installation

Install via NPM/Yarn:

  1. npm install jalali-date

You could grab the latest version from lib directory and use it:

  1. <head>
  2. <script src="jdate.js" type="text/javascript" charset="utf-8"></script>
  3. <script src="jdate.min.js" type="text/javascript" charset="utf-8"></script>
  4. </head>

The full-version is useful for debugging. You may want to use minified version in production as it is smaller.

Initialization

For initializing JDate you may either pass an array of Jalali date to it or a Date object. If no parameter is passed, the default is today:

  1. const JDate = require('jalali-date');
  2. const jdate = new JDate; // => default to today
  3. const jdate2 = new JDate(1393, 10, 11);
  4. const jdate3 = new JDate([1393, 10, 11]);
  5. const jdate4 = new JDate(new Date(2014, 1, 3));

API

  1. jdate.date //=> [1393, 5, 13] An Array of Jalali Date
  2. jdate._d // => Gregorian Date Object
  3. // Getters
  4. jdate.getFullYear() // => 1393
  5. jdate.getMonth() // => 5
  6. jdate.getDate() // => 13
  7. jdate.getDay() // => 1
  8. // Setters
  9. jdate.setFullYear(1394)
  10. jdate.setMonth(6)
  11. jdate.setDate(12)
  12. // Formatting output
  13. jdate.format('dddd DD MMMM YYYY') // => پنج‌شنبه 12 شهریور 1394
  14. // Static functions
  15. JDate.isLeapYear(1393) // => false
  16. JDate.daysInMonth(1393, 5) // => 31
  17. JDate.toGregorian(1393, 12, 11) // => Gregorian Date object
  18. JDate.toJalali(new Date) // => JDate object

Formatting output

Use format() and following conversion identifiers as follows:

  1. date.format('dddd DD MMMM YYYY') //=> دوشنبه 6 امرداد 1393

The conversion identifiers are as follows:

Identifier Description Example
YYY or YYYY Full Year (4 digits) 1393
YY Year (2 digits) 93
M Month in number returns 5 for امرداد
MM Month in number returns 05 for امرداد
MMM or MMMM Month in string امرداد
D Day in number 26
DD Day in number 06
d or dd Abbreviation of day name in string ۱ش (for یکشنبه)
ddd or dddd Full day name in string یکشنبه

Contribute

Report bugs and suggest feature in issue tracker. Feel free to Fork and send Pull Requests.

License

MIT