• Formats a date and/or time using custom formatting logic based on dateStyle and timeStyle.

    Uses explicit Intl.DateTimeFormat options for full control over the output format.

    • "short" date is always dd/mm/yyyy
    • "short" time is always 12-hour format (e.g., 11:59 PM)
    • Supports combining both formats into a single string

    Example Output

    formatDateTime(new Date("2025-12-31T23:59:59"), {
    dateStyle: "short",
    timeStyle: "short"
    }); // "31/12/2025, 11:59 PM"

    formatDateTime(new Date("2025-12-31T23:59:59"), {
    dateStyle: "medium",
    timeStyle: "medium"
    }); // "Dec 31, 2025, 11:59:59 PM"

    formatDateTime(new Date("2025-12-31T23:59:59"), {
    dateStyle: "long",
    timeStyle: "long"
    }); // "December 31, 2025, 11:59:59 PM EST"

    formatDateTime(new Date("2025-12-31T23:59:59"), {
    dateStyle: "full",
    timeStyle: "full"
    }); // "Wednesday, December 31, 2025, 11:59 PM Eastern Standard Time"

    formatDateTime(new Date("2025-12-31T23:59:59"), {
    timeStyle: "short"
    }); // "11:59 PM"

    Parameters

    • Optional date: number | Date

      The Date object or timestamp to format.

    • options: FormatDateTimeOptions = ...

      Formatting options.

    Returns string

    A string representing the formatted date and/or time.