The SimpleDateFormat class serves as a wrapper for the Moment.js library. It mimics the functionality of java.text.SimpleDateFormat, providing a familiar interface for Java developers.

To learn more about Moment.js, refer to its official documentation.

Hierarchy

  • SimpleDateFormat

Methods

Methods

  • Converts the provided date into a string representation based on the specified format.

    Parameters

    • Optional input: Date

      The date to be formatted. If not provided, the current date and time will be used.

    Returns string

    The formatted date as a string.

    Example

    // Create a SimpleDateFormat instance with the desired format
    const formatter = new ix.api.text.SimpleDateFormat("dd.MM.yyyy");

    // Format a specific date
    const formattedDate = formatter.format(new Date(2021, 1 - 1, 01));
    console.log(formattedDate); // Outputs: "01.01.2021"
  • Parses the provided string into a Date object based on the format specified when the SimpleDateFormat instance was created.

    Parameters

    • input: string

      The string to be parsed into a Date object.

    • Optional baseDate: Date

      An optional base date used for parsing. If not provided, the current date and time will be used.

    Returns undefined | Date

    A Date object representing the parsed date, or undefined if the input string cannot be parsed into a valid date.

    Example

    // Create a SimpleDateFormat instance with the desired format
    const formatter = new ix.api.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

    // Parse a string into a Date object
    const parsedDate = formatter.parse("2021-01-01T20:55:43.000Z");
    console.log(parsedDate);
    // Outputs: Fri Jan 01 2021 20:55:43 GMT+0100 (Central European Standard Time)