mazey
    Preparing search index...

    Function formatDate

    • Return the formatted date string in the given format.

      Supported format tokens:

      Token Meaning Range or example
      yyyy Four-digit year 2022
      MM Two-digit month 0112
      dd Two-digit day of the month 0131
      HH Two-digit hour using the 24-hour clock 0023
      hh Two-digit hour using the 12-hour clock 0112
      mm Two-digit minute 0059
      ss Two-digit second 0059
      a Uppercase meridiem indicator AM or PM

      The function creates a native Date and reads its local date and time fields. Timestamp output can therefore differ between runtime time zones.

      Usage:

      import { formatDate } from "mazey";

      const ret1 = formatDate();
      const ret2 = formatDate("Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)", "yyyy-MM-dd hh:mm:ss a");
      const ret3 = formatDate(1641881235000, "yyyy-MM-dd hh:mm:ss a");
      const ret4 = formatDate(new Date(2014, 1, 11), "MM/dd/yyyy");
      console.log("Default formatDate value:", ret1);
      console.log("String formatDate value:", ret2);
      console.log("Number formatDate value:", ret3);
      console.log("Date formatDate value:", ret4);

      Output:

      Default formatDate value: 2023-01-11
      String formatDate value: 2022-01-11 02:12:26 PM
      Number formatDate value: 2022-01-11 02:07:15 PM
      Date formatDate value: 02/11/2014
      

      Parameters

      • OptionaldateIns: MazeyDate

        Original date value. Defaults to the current date and time.

      • format: string = "yyyy-MM-dd"

        Format string composed of supported format tokens. Defaults to yyyy-MM-dd.

      Returns string

      The formatted date string.

      If dateIns is not a valid date.