Javascript library to represent and work with dates in different calendar systems (e.g. hijri, persian and others).
- Simple and type-safe API
- Immutable objects
- Supports 7 calendar systems
- Tiny: 1kB (minified + gzipped)
- Zero dependencies. Leverages
Intl.DateTimeFormat.
- gregorian
- islamic
- islamic-umalqura
- islamic-rgsa
- islamic-civil
- islamic-tbla
- persian
$ npm install intl-dateconstdate=IntlDate.of('islamic-umalqura',1377,3,22);date.toString('gregorian');// 1957-10-16date.getYear('gregorian');// 1957date.getMonth('gregorian');// 10date.getDay('gregorian');// 16date.toString('islamic-umalqura');// 1377-03-22date.getYear('islamic-umalqura');// 1377date.getMonth('islamic-umalqura');// 3date.getDay('islamic-umalqura');// 22date.toString('persian');// 1336-07-24date.getYear('persian');// 1336date.getMonth('persian');// 7date.getDay('persian');// 24constdate=IntlDate.of('islamic-umalqura',1377,3,22);constjsDate=newDate(2017,11,25);constintlDate=IntlDate.from(jsDate);constdate=IntlDate.parse('gregorian','1957-05-16');constdate=IntlDate.today();constyear=date.getYear('islamic-umalqura');constmonth=date.getMonth('gregorian');constday=date.getDay('persian');constdayOfWeek=date.getDayOfWeek();constquarter=date.getQuarter('gregorian');constoldDate=IntlDate.of('gregorian',1957,10,16);constnewDate=oldDate.plusDays(20);oldDate.toString('gregorian');// 1957-10-16newDate.toString('gregorian');// 1957-11-05constoldDate=IntlDate.of('gregorian',1957,10,16);constnewDate=oldDate.minusDays(20);oldDate.toString('gregorian');// 1957-10-16newDate.toString('gregorian');// 1957-09-26constdate1=IntlDate.of('gregorian',1957,10,16);constdate2=IntlDate.of('islamic-umalqura',1377,3,22);constresult=date1.isEqual(date2);// trueconstdate1=IntlDate.of('gregorian',1957,10,15);constdate2=IntlDate.of('islamic-umalqura',1377,3,22);constresult=date1.isBefore(date2);// trueconstdate1=IntlDate.of('gregorian',1957,10,17);constdate2=IntlDate.of('islamic-umalqura',1377,3,22);constresult=date1.isAfter(date2);// trueconstdate1=IntlDate.of('gregorian',1957,10,16);constdate2=IntlDate.of('gregorian',1957,10,20);constdate3=IntlDate.of('gregorian',1957,10,25);constresult=date2.isBetween(date1,date3);// trueconstdate1=IntlDate.of('gregorian',1957,10,16);constdate2=IntlDate.of('gregorian',1957,11,20);constdays=date1.daysUntil(date2);// 35constdate1=IntlDate.of('gregorian',1957,10,16);constdate2=IntlDate.of('gregorian',1957,10,20);constmin=IntlDate.min(date1,date2);// date1constdate1=IntlDate.of('gregorian',1957,10,16);constdate2=IntlDate.of('gregorian',1957,10,20);constmax=IntlDate.max(date1,date2);// date2constdate=IntlDate.of('gregorian',2022,7,11);constformattedString=date.format('gregorian','yyyy-MM-dd');// 2022-07-11constdate=IntlDate.of('gregorian',2022,7,11);conststring=date.toString('gregorian');// 2022-07-11Copyright 2022 Khalid H. Alharisi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.