Methods
date.setMonth()
Set the Bikram Sambat month index on a NepaliDate instance with automatic day clamping.
The setMonth method updates the Bikram Sambat month for the current NepaliDate instance using a zero based month index from 0 for Baisakh to 11 for Chaitra. If the current day exceeds the total days in the destination month, the day is automatically clamped to the final valid day of that month.
Import
import { NepaliDate } from "nepali-date-library";Signature
setMonth(month: number): void;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
month | number | Yes | 0-indexed month integer (0 for Baisakh to 11 for Chaitra). |
Return Value
- Type:
void - Mutates the current
NepaliDateinstance in place.
Exceptions
| Error Message | Trigger Condition |
|---|---|
Invalid nepali month must be between 1 - 12 | Thrown if month is outside 0 to 11. |
Example
import { NepaliDate } from "nepali-date-library";
// 2081 Baisakh 15 (month index 0)
const date = new NepaliDate("2081-01-15");
// Shift to Shrawan (month index 3)
date.setMonth(3);
console.log(date.format("YYYY-MM-DD")); // "2081-04-15"Related
date.getMonth(): Retrieve the current month index.date.setDate(): Mutate the day component.
Advertisement
date.setYear()
Set the Bikram Sambat year on a NepaliDate instance within the supported calendar range.
date.setDate()
Set the day of the month on a NepaliDate instance and recalculate its timestamp.