Function convertDateToString

  • Returns the string representation of the given date. The format of the output string can be specified:

    • 'date' for a date-only string (YYYY-MM-DD),
    • 'time' for a time-only string (HH:mm:ss), or
    • 'date-time' for a full date-time string in ISO format (YYYY-MM-DDTHH:mm:ss.sssZ). If no format is specified, the full date-time ISO string is returned by default.

    Parameters

    • date: Date
    • Optional format: "date" | "time" | "date-time"

    Returns string

    A string representation of the date in the specified format.

    Example

    // returns '2023-11-09'
    convertDateToString(new Date('2023-11-09T14:22:54.131Z'), 'date');

    Example

    // returns '14:22:54'
    convertDateToString(new Date('2023-11-09T14:22:54.131Z'), 'time');

    Example

    // returns '2023-11-09T14:22:54.131Z'
    convertDateToString(new Date('2023-11-09T14:22:54.131Z'), 'date-time');

    Example

    // returns '2023-11-09T14:22:54.131Z'
    convertDateToString(new Date('2023-11-09T14:22:54.131Z'));

Generated using TypeDoc