• Converts the passed in date/time into formatted date and time strings that match the configured date and time formats or the passed in format string.

    • Any missing date/time parameters will default to a value of 0.
    • If the date/time parameters are negative, their value will be set to 0. The exception to this is the year parameter, it can be negative.
    • If the date/time parameters are set to a value greater than possible (eg. the 20th month in a calendar that only has 12 months, or the 34th hour when a day can only have 24 hours) the max value will be used.

    Returns

    If no format string is provided an object with the date and time formatted strings, as set in the configuration, will be returned. If a format is provided then a formatted string will be returned.

    Examples

    // Assuming that the default date and time formats are in place
    // Date: Full Month Name Day, Year
    // Time: 24Hour:Minute:Second

    SimpleCalendar.api.formatDateTime({year: 2021, month: 11, day: 24, hour: 12, minute: 13, seconds: 14});
    // Returns {date: 'December 25, 2021', time: '12:13:14'}

    SimpleCalendar.api.formatDateTime({year: -2021, month: -11, day: 24, hour: 12, minute: 13, seconds: 14})
    // Returns {date: 'January 25, -2021', time: '12:13:14'}

    SimpleCalendar.api.formatDateTime({year: 2021, month: 111, day: 224, hour: 44, minute: 313, seconds: 314})
    // Returns {date: 'December 31, 2021', time: '23:59:59'}

    SimpleCalendar.api.formatDateTime({year: 2021, month: 111, day: 224, hour: 44, minute: 313, seconds: 314},"DD/MM/YYYY HH:mm:ss A")
    // Returns "31/12/2021 23:59:00 PM"

    Parameters

    • date: DateTimeParts

      A date object (eg {year:2021, month: 4, day: 12, hour: 0, minute: 0, seconds: 0}) with the parameters set to the date and time that should be formatted.
      Important: The month and day are index based so January would be 0 and the first day of the month will also be 0.

    • format: string = ''

      Optional format string to return custom formats for the passed in date and time.

    • calendarId: string = 'active'

      Optional parameter to specify the ID of the calendar to use when converting a date to a formatted string. If not provided the current active calendar will be used.

    Returns string | {
        date: string;
        time: string;
    }