Design & Download
Your JS Library
in Seconds!!!

Snippet: isoDate()

Written by Christopher West (cwest) on November 17, 2015.
Gets the date in the ISO-8601 standard format: YYYY-MM-DDTHH:mm:ss.sssZ
function isoDate(opt_date) {
  opt_date = opt_date || new Date;
  return opt_date.getUTCFullYear() + "-"
    + ("0" + (opt_date.getUTCMonth() + 1) + "-").slice(-3)
    + ("0" + opt_date.getUTCDate() + "T").slice(-3)
    + ("0" + opt_date.getUTCHours() + ":").slice(-3)
    + ("0" + opt_date.getUTCMinutes() + ":").slice(-3)
    + ("0" + opt_date.getUTCSeconds() + ".").slice(-3)
    + ("00" + opt_date.getUTCMilliseconds() + "Z").slice(-4);
}

isoDate() API Documentation

Description

Gets the date in the ISO-8601 standard format: YYYY-MM-DDTHH:mm:ss.sssZ

Parameters

  1. opt_date {Date}:
    Optional. Defaults to the current date/time. The date to be formatted using the ISO-8601.

Returns

Returns the specified date in the ISO-8601 standard format.