The Nepali Date API offers functions for converting between Nepali Bikram Sambat and Gregorian dates, along with date formatting, parsing, and manipulation. It simplifies working with the Nepali calendar, providing accurate tools for date conversion and handling.
Methods
The following methods are available:
Method | Return Type | Description |
---|---|---|
getFullYear() | string | number | Gets the year, using local time. |
getMonth() | string | number | Gets the month of a Date object. |
getMonthName() | string | Gets the name of the month of a Date object. |
getDate() | string | number | Gets the day-of-the-month. |
getDay() | string | number | Gets the day of the week. |
getDayName() | string | Gets the short name of day of the week. |
getDayNameFull() | string | Gets the full name of day of the week. |
now() | NepaliDate | Returns the current nepali date. |
parseDate(date:string) | {year : number, date : number, day : number} | Returns the parsed date object from string of format YYYY-MM-DD. |
toAD() | Object | Returns the year, month and date in AD |
toADasDate() | DateObject | Returns the date object for Gregorian Calendar. |
toJson() | Nepali date in JSON format. | Returns the date object for Nepali date as JSON. |
toString() | Nepali date in string format. | Returns the date object for Nepali date as string in format YYYY-MM-DD. |
format(format:string) | Nepali date in provided format pattern. | Formats date in given string format pattern. eg. (YYYY/MM/DD), (MMMM DD, YYYY, dddd). |
API to format date based on the string token provided.
The following are the available formats:
Format | Output | Description |
---|---|---|
d | 0-6 | The day of the week, with Sunday as 0 |
dd | Su-Sa | The min name of the day of the week |
ddd | Sun-Sat | The short name of the day of the week |
dddd | Sunday-Saturday | The full name of the day of the week |
D | 1-31 for AD and 1-32 for BS | The day of the month |
DD | 01-31 for AD and 01-32 for BS | The day of the month in 2 digits. |
M | 1-12 | The month of the year. |
MM | 01-12 | The month of the year in 2 digits. |
MMM | Bai-Cha | Short name of month |
MMMM | Baishak-Chaitra | Full name of month |
YY | 81 | Year in two digits. |
YYYY | 2081 | Year in four digits. |
API to manipulate date.
The available units are 'day', 'd', 'week', 'w', 'month', 'm', 'year', 'y'.
The following are the available date manipulation methods:
Method | Return Type | Description |
---|---|---|
add(value:number, type:unit) | NepaliDate | Adds the given value to the date and returns new NepaliDate instance. |
subtract(value:number, type:unit) | NepaliDate | Subtract the given value from the date and returns new NepaliDate instance. |
setDate(value:number) | undefined | This method of NepaliDate instances changes the day of the month for this date. |
setMonth(value:number) | undefined | This method of NepaliDate instances changes the month of the year for this date. |
setFullYear(value:number) | undefined | This method of NepaliDate instances changes the year for this date. |
The Nepali Date API provides some extra useful methods like formatADDate()
, toAD()
and toBS()
.
Following are some extra methods available in Nepali date api.
Method | Return Type | Description |
---|---|---|
formatADDate(date:Date, format?:string, lang?:ILang) | Formatted string date. | Formats date in given string format pattern. eg. (YYYY/MM/DD), (MMMM DD, YYYY, dddd) and so on. |
toAD(date:string) | Object | Returns the year, month and date in AD |
toBS(date:string) | Object | Returns the year, month and date in BS |