Methods
date.setYear()
Set the Bikram Sambat year on a NepaliDate instance within the supported calendar range.
The setYear method updates the four digit Bikram Sambat year on the current NepaliDate instance and adjusts the timestamp accordingly. The target year must fall within the supported range between 1976 and 2100 BS.
Import
import { NepaliDate } from "nepali-date-library";Signature
setYear(year: number): void;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
year | number | Yes | 4-digit Bikram Sambat year (1976 to 2100). |
Return Value
- Type:
void - Mutates the current
NepaliDateinstance in place.
Exceptions
| Error Message | Trigger Condition |
|---|---|
Nepal year out of range | Thrown if year is earlier than 1976 BS or later than 2100 BS. |
Example
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate("2080-01-01");
date.setYear(2082);
console.log(date.format("YYYY-MM-DD")); // "2082-01-01"Related
date.getYear(): Retrieve the current year.date.set(): Set year, month, and day together.
Advertisement
date.set()
Set year, month, and day coordinates simultaneously on a NepaliDate instance.
date.setMonth()
Set the Bikram Sambat month index on a NepaliDate instance with automatic day clamping.