mazey
    Preparing search index...

    Function formatLocalDateTime

    • Format a Date as an HTML datetime-local value using local fields.

      Precision Output shape
      minute YYYY-MM-DDTHH:mm
      second YYYY-MM-DDTHH:mm:ss
      millisecond YYYY-MM-DDTHH:mm:ss.SSS

      Usage:

      import { formatLocalDateTime } from "mazey";

      const date = new Date(2026, 6, 21, 14, 30, 45, 123);
      const minutes = formatLocalDateTime(date);
      const seconds = formatLocalDateTime(date, { precision: "second" });
      const milliseconds = formatLocalDateTime(date, {
      precision: "millisecond",
      });
      console.log(minutes);
      console.log(seconds);
      console.log(milliseconds);

      Output:

      2026-07-21T14:30
      2026-07-21T14:30:45
      2026-07-21T14:30:45.123
      

      Parameters

      • date: Date

        A valid Date to format.

      • options: { precision?: LocalDateTimePrecision } = {}

        Formatting options. Precision defaults to minute.

      Returns string

      A normalized HTML datetime-local value containing local calendar fields. The year is padded to at least four digits.

      If date is not a Date or precision is unsupported.

      If date is invalid or its local year is earlier than 1.

      This function does not call toISOString() and does not convert the value to UTC. It does not mutate the supplied Date.