Skip to main content

format

@brightsoftware/date-np


@brightsoftware/date-np / src / format

Function: format()

format(date, formatString): string

Defined in: src/format.ts:102

Format a date using the specified format string

Parameters

date

The date to format (Date or NepaliDate)

Date | NepaliDate

formatString

string

The format string with tokens

Returns

string

Formatted date string

Example

// English date
format(new Date(2025, 5, 3), 'yyyy-MM-dd') // '2025-06-03'
format(new Date(2025, 5, 3), 'MMMM do, yyyy') // 'June 3rd, 2025'

// Nepali date
format(new NepaliDate(2082, 2, 20), 'yyyy-MM-dd') // '2082-03-20'
format(new NepaliDate(2082, 2, 20), 'MMMM do, yyyy') // 'Aashar 20th, 2082'