Nepali DateNepali DateBikram Sambat Date Engine
Methods

date.parse()

Parse a formatted Bikram Sambat date string and update the current date instance in place.

The parse method parses a Bikram Sambat date string and updates the coordinates of the current NepaliDate instance in place. It supports various delimiter styles including slashes, dots, and hyphens, recalculating the underlying timestamp upon successful parsing.


Import

import { NepaliDate } from "nepali-date-library";

Signature

parse(dateString: string): void;

Parameters

ParameterTypeRequiredDescription
dateStringstringYesDate string formatted as YYYY-MM-DD, YYYY/MM/DD, or YYYY.MM.DD.

Return Value

  • Type: void
  • Mutates the current NepaliDate instance in place.

Exceptions

Error MessageTrigger Condition
Invalid dateThrown if string segments are non-numeric.
Nepal year out of rangeThrown if the parsed year is outside 1976 to 2100 BS.
Invalid nepali month must be between 1 - 12Thrown if month is outside 1 to 12.
Invalid nepali date must be between 1 - <max> in <year> <month>Thrown if day exceeds the month's verified length.

Example

import { NepaliDate } from "nepali-date-library";

const date = new NepaliDate();

// Mutate instance from string
date.parse("2081-07-15");
console.log(date.format("YYYY-MM-DD")); // "2081-07-15"

// Delimiters with slash or period are supported
date.parse("2082/01/01");
console.log(date.format("YYYY-MM-DD")); // "2082-01-01"

Advertisement

On this page