Function persianDateGenerator

  • Generates a formatted Persian date string from a given Date object.

    Parameters

    • date: Date

      The Date object to be formatted.

    • OptionalnoWeekDay: boolean

      Optional. If true, includes the weekday in the formatted string. Default is false.

    • showTime: boolean = false

      Optional. If true, includes the time in the formatted string. Default is false.

    Returns string

    A formatted Persian date string. If the date is invalid, returns '--/--/----'.

    const date = new Date('2023-10-05T14:48:00');
    const formattedDate = persianDateGenerator(date, false, true);
    console.log(formattedDate); // Outputs: "پنجشنبه 13 مهر 1402 - 14:48"