Methods
date.getEnglishDate()
Retrieve the equivalent Gregorian date as a native JavaScript Date object.
The getEnglishDate method returns the native JavaScript Date object corresponding to the current NepaliDate instance. This allows seamless integration with third party libraries, databases, and standard browser APIs that expect a native Gregorian Date object.
Import
import { NepaliDate } from "nepali-date-library";Signature
getEnglishDate(): Date;Parameters
- None.
Return Value
- Type:
Date - Description: A standard JavaScript
Dateinstance calibrated in UTC.
Examples
Converting to Native JavaScript Date
import { NepaliDate } from "nepali-date-library";
const nepaliDate = new NepaliDate("2081-07-15");
const jsDate = nepaliDate.getEnglishDate();
console.log(jsDate instanceof Date); // true
console.log(jsDate.toISOString()); // "2024-10-31T00:00:00.000Z"
console.log(jsDate.getUTCFullYear()); // 2024
console.log(jsDate.getUTCMonth()); // 9 (October, 0-indexed)
console.log(jsDate.getUTCDate()); // 31Passing to Third-Party Date Utilities
import { NepaliDate } from "nepali-date-library";
const date = new NepaliDate("2081-01-01");
const englishDate = date.getEnglishDate();
// Interoperable with Intl.DateTimeFormat or external libraries
const formatted = new Intl.DateTimeFormat("en-US", {
dateStyle: "full",
timeZone: "UTC",
}).format(englishDate);
console.log(formatted); // "Saturday, April 13, 2024"Related
BStoAD(): Standalone helper returning a formatted string instead of aDateobject.new NepaliDate(date): Constructing aNepaliDatefrom a JavaScriptDate.
Advertisement
date.getTime()
Retrieve the numeric timestamp in milliseconds since the Unix epoch.
date.set()
Set year, month, and day coordinates simultaneously on a NepaliDate instance.