• Formats a time according to the specified timeStyle and locale.

    Uses Intl.DateTimeFormat internally.

    Example Output

    formatTime(new Date("2025-12-31T23:59:59"), { timeStyle: "short" });  // "11:59 PM"
    formatTime(new Date("2025-12-31T23:59:59"), { timeStyle: "medium" }); // "11:59:59 PM"
    formatTime(new Date("2025-12-31T23:59:59"), { timeStyle: "long" }); // "11:59:59 PM EST"
    formatTime(new Date("2025-12-31T23:59:59"), { timeStyle: "full" }); // "11:59 PM Eastern Standard Time"

    Parameters

    • Optional date: number | Date

      The date object or timestamp to extract the time from.

    • options: FormatTimeOptions = ...

      Options to customize time formatting.

    Returns string

    A formatted time string.