@flightlesslabs/utils - v0.3.0
    Preparing search index...

    Function getMoment

    • Creates a dayjs instance with optional format parsing, timezone handling, or UTC output.

      This is a thin wrapper around dayjs that adds:

      • Parsing with custom formats
      • Timezone conversion
      • UTC mode

      Parameters

      • Optionaldate: null | string | number | Date | Dayjs

        The input date, timestamp, or string to parse.

      • Optionalformat: GetMomentFormat

        Optional format string to assist parsing.

      • Optionalsettings: GetMomentSettings

        Optional settings to control timezone or UTC output.

      Returns Dayjs

      A dayjs instance in local time, UTC, or the specified timezone.

      • Requires the utc, timezone, and customParseFormat plugins (already preconfigured).
      • If utc is true, the timezone setting is ignored.

      Import:

      import { getMoment } from "@flightlesslabs/utils";
      

      Basic output:

      import { getMoment } from "@flightlesslabs/utils";

      const basicTime = getMoment();
      console.log(utcTime.format('DD-MM-YYYY)); // "01-02-2025"

      UTC output:

      import { getMoment } from "@flightlesslabs/utils";

      const utcTime = getMoment("2025-01-01T12:00:00Z", undefined, { utc: true });
      console.log(utcTime.format()); // "2025-01-01T12:00:00Z"

      Timezone output:

      import { getMoment } from "@flightlesslabs/utils";

      const kolkataTime = getMoment("01-01-2025", "DD-MM-YYYY", { timezone: "Asia/Kolkata" });
      console.log(kolkataTime.format()); // "2025-01-01T00:00:00+05:30"