Constructors

  • String

    Provide a valid Nepali date string. The current supported formats are:

    YYYY/MM/DD
    YYYY-MM-DD
    YYYY MM DD
    DD/MM/YYYY
    DD-MM-YYYY
    DD MM YYYY

    Example:

    new NepaliDate('2051/02/01') // YYYY/MM/DD
    new NepaliDate('2051-02-01')
    new NepaliDate('2051 02 01')
    new NepaliDate('01/02/2051') // DD/MM/YYYY
    new NepaliDate('01-02-2051')
    new NepaliDate('01 02 2051')

    Number

    The number value represents the UTC timestamp that will be converted to Nepali date.

    Example:

    new NepaliDate(1589638162879)
    

    Date

    Javascript Date object

    Example:

    new NepaliDate(new Date(2020, 10, 10))
    

    Empty constructor

    If no values are provided, the current day date will be converted to Nepali date.

    new NepaliDate()
    

    Parameters

    • Optional value: string | number | Date

    Returns default

  • This constructor takes year, monthIndex i.e 0-11, and date.

    Example:

    new Date(2051, 0, 1) // Baisakh 1, 2051
    

    Parameters

    • year: number
    • monthIndex: number
    • date: number

    Returns default

Properties

[dateSymbol]: number
[daySymbol]: number
[jsDateSymbol]: Date
[monthSymbol]: number
[yearSymbol]: number
language: "en" | "np" = Language.en

Default language for formatting. Set the value to 'np' for default nepali formatting.

Methods

  • Parameters

    • year: number
    • month: number = 0
    • date: number = 1
    • day: number = 0

    Returns void

  • Format Nepali date string based on format string.

    YYYY - 4 digit of year (2077)
    YYY - 3 digit of year (077)
    YY - 2 digit of year (77)
    M - month number (1 - 12)
    MM - month number with 0 padding (01 - 12)
    MMM - short month name (Bai, Jes, Asa, Shr, etc.)
    MMMM - full month name (Baisakh, Jestha, Asar, ...)
    D - Day of Month (1, 2, ... 31, 32)
    DD - Day of Month with zero padding (01, 02, ...)
    d - Week day (0, 1, 2, 3, 4, 5, 6)
    dd - Week day in short format (Sun, Mon, ..)
    ddd - Week day in long format (Sunday, Monday, ...)

    Set language to 'np' for nepali format. The strings can be combined in any way to create desired format.

    let a = new NepaliDate(2054,10,10);
    a.format('YYYY/MM/DD') // '2054/11/10'
    a.format('YYYY MM DD') // '2054 11 10'
    a.format('YYYY') // '2054'
    a.format('ddd DD, MMMM YYYY') // 'Sunday 10, Falgun 2054'
    a.format('To\\day is ddd DD, MMMM YYYY') // 'Today is Sunday 10, Falgun 2054', Note: use '\\' to escape [YMDd]
    a.format('DD/MM/YYYY', 'np') //' १०/११/२०५४'
    a.format('dd', 'np') // 'आइतबार'
    a.format('ddd DD, MMMM YYYY','np') // 'आइतबार १०, फाल्गुण २०५४'
    // Set static variable to 'np' for default Nepali language
    NepaliDate.language = 'np'
    a.format('ddd DD, MMMM YYYY') // 'आइतबार १०, फाल्गुण २०५४'

    Parameters

    • formatString: string
    • language: "en" | "np" = NepaliDate.language

      en | np

    Returns string

  • Returns AD date fields in an object implementing IYearMonthDate

    {
    year: 2019,
    month: 10,
    date: 10,
    day: 0
    }

    Returns IYearMonthDate

  • Returns Nepali date fields in an object implementing IYearMonthDate

    {
    year: 2052,
    month: 10,
    date: 10,
    day: 0
    }

    Returns IYearMonthDate

  • Returns an object with AD and BS object implementing IYearMonthDate

    Example:

    {
    BS: {
    year: 2052,
    month: 10,
    date: 10,
    day: 0
    },
    AD: {
    year: 2019,
    month: 10,
    date: 10,
    day: 0
    },

    }

    Returns IAdBs

  • Get Nepali month index.

    Baisakh => 0
    Jestha => 1
    Asar => 2
    Shrawan => 3
    Bhadra => 4
    Aswin => 5
    Kartik => 6
    Mangsir => 7
    Poush => 8
    Magh => 9
    Falgun => 10
    Chaitra => 11

    Returns number

  • Set date in the current date object. It can be positive or negative. Positive values within the month will update the date only and more then month mill increment month and year. Negative value will deduct month and year depending on the value. It is similar to javascript Date API.

    Example:

    let a = new NepaliDate(2054,10,10);
    a.setDate(11); // will make date NepaliDate(2054,10,11);
    a.setDate(-1); // will make date NepaliDate(2054,9,29);
    a.setDate(45); // will make date NepaliDate(2054,10,15);

    Parameters

    • date: number

      positive or negative integer value to set date

    Returns void

  • Set month in the current date object. It can be positive or negative. Positive values within the month will update the month only and more then month mill increment month and year. Negative value will deduct month and year depending on the value. It is similar to javascript Date API.

    Example:

    let a = new NepaliDate(2054,10,10);
    a.setMonth(1); // will make date NepaliDate(2054,11,10);
    a.setMonth(-1); // will make date NepaliDate(2053,11,10);
    a.setMonth(12); // will make date NepaliDate(2054,0,10);

    Parameters

    • month: number

    Returns void

  • Set year in the current date object. It only takes positive value i.e Nepali Year

    Example:

    let a = new NepaliDate(2054,10,10);
    a.setYear(2053); // will make date NepaliDate(2053,10,15);

    Parameters

    • year: number

    Returns void

  • Returns new converted Nepali Date from the provided Javascript Date. It is similar to passing string as constructor

    Parameters

    • date: Date

    Returns default

  • Returns new Nepali Date from the string date format Similar to calling constructor with string parameter

    Parameters

    • dateString: string

    Returns default

Generated using TypeDoc