function truncatedISO8061Date(date, withMilliseconds = true) {
    // Date.toISOString() will return like "2018-10-29T06:34:36.139Z"
    const dateString = date.toISOString();
    return withMilliseconds
        ? dateString.substring(0, dateString.length - 1) + "0000" + "Z"
        : dateString.substring(0, dateString.length - 5) + "Z";
}
Rounds a date off to seconds.

@param date -
@param withMilliseconds - If true, YYYY-MM-DDThh:mm:ss.fffffffZ will be returned;
                                         If false, YYYY-MM-DDThh:mm:ssZ will be returned.
@returns Date string in ISO8061 format, with or without 7 milliseconds component