Function formatDateTimeByString

  • Formats a date string into a specified date time format

    Parameters

    • dateString: string

      A string representing the date.

    • Optional formatter: string

      Optional. A specific format string to format the date. Defaults to 'YYYY-MM-DD HH:mm:ss'.

    Returns string

    The formatted date string.

    Throws

    Throws an error if the date string is invalid or cannot be parsed into a Date object.

    Example

    const dateString = '2024-02-19T10:30:00Z';
    const formattedDateTime = formatDateTimeByString(dateString, 'MMMM D, YYYY, h:mm A');
    console.log(formattedDateTime);