Instance Properties
Reference for public instance properties available on every NepaliDate object including year, month, day, and underlying timestamp.
Every NepaliDate instance provides direct read access to its core calendar coordinates through public properties. These include the four digit Bikram Sambat year, the month number indexed from 0 to 11, the day of the month from 1 to 32, and the underlying UTC timestamp stored as a native JavaScript Date object. These properties reflect the current state of the date instance after any modifications or arithmetic operations.
Property Reference
| Property | Type | Description | Range |
|---|---|---|---|
year | number | The Bikram Sambat year. | 1976 – 2100 |
month | number | The 0-indexed Bikram Sambat month. | 0 (Baisakh) – 11 (Chaitra) |
day | number | The day of the month. | 1 – 32 |
timestamp | Date | The corresponding native JavaScript Date object in UTC. | Equivalent Gregorian timestamp |
Examples
Reading Properties Directly
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate("2081-07-15");
console.log(date.year); // 2081
console.log(date.month); // 6 (0-indexed: 6 corresponds to Kartik)
console.log(date.day); // 15
console.log(date.timestamp); // 2024-10-31T00:00:00.000ZDirect Property vs. Method Access
While properties are public for inspection, it is recommended to use dedicated methods for formatting and mutation:
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate("2081-07-15");
// Using methods for formatted values
console.log(date.getDate()); // 15
console.log(date.getMonth() + 1); // 7 (1-indexed display)
// Using methods to mutate coordinates safely
date.setDate(16); // Safely validates days in month and recalculates timestampRelated
new NepaliDate(): Instantiating aNepaliDateobject.date.getEnglishDate(): Retrieve the native JavaScriptDate.
new NepaliDate()
Constructor overloads and initialization options for creating NepaliDate instances in Node.js and TypeScript.
date.getYear()
Retrieve the four digit Bikram Sambat year number from a NepaliDate instance.