Nodejs Utililty Methods Date ISO Format

List of utility methods to do Date ISO Format

Description

The list of methods to do Date ISO Format are organized into topic(s).

Method

getISO8601()
Date.prototype.getISO8601 = function () {
  var month = (this.getMonth() + 1 < 10) ? "0" + this.getMonth() + 1 : this.getMonth() + 1;
  var day = (this.getDate() < 10) ? "0" + this.getDate() : this.getDate();
  var hours = (this.getHours() < 10) ? "0" + this.getHours() : this.getHours();
  var minutes = (this.getMinutes() < 10) ? "0" + this.getMinutes() : this.getMinutes();
  var seconds = (this.getSeconds() < 10) ? "0" + this.getSeconds() : this.getSeconds();
  var offset = this.getTimezoneOffset() / 60;
  return this.getFullYear() + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "-0" + offset + "00";
};
...
getISODate()
Date.prototype.getISODate = function()
  var mth = this.getMonth() + 1;
  mth = (mth < 10 ? '0' : '') + mth;
  var date = this.getDate();
  date = (date < 10 ? '0' : '') + date;
  return this.getFullYear() + mth + date;
};
getISODate()
Date.prototype.getISODate = function () {
  let month = this.getMonth() + 1;
  if (month < 10) month = '0' + month;
  let day = this.getDate();
  if (day < 10) day = '0' + day;
  return this.getFullYear() + '-' + month + '-' + day;
};
getISODay()
Date.prototype.getISODay = function(){
    return (this.getDay() + 6) % 7;
getISOWeek()
Date.prototype.getISOWeek = function () {
  var target = new Date(this.valueOf());
  var dayNr = (this.getDay() + 6) % 7;
  target.setDate(target.getDate() - dayNr + 3);
  var firstThursday = target.valueOf();
  target.setMonth(0, 1);
  if (target.getDay() != 4) {
    target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
  return 1 + Math.ceil((firstThursday - target) / 604800000);
getISOYear()
Date.prototype.getISOYear = function () {
  var target  = new Date(this.valueOf());
  target.setDate(target.getDate() - ((this.getDay() + 6) % 7) + 3);
  return target.getFullYear();
iso8601()
Date.prototype.iso8601 = function () {
    return this.getUTCFullYear() + '-' +
        (this.getUTCMonth() + 1).zfill(2) + '-' +
        this.getUTCDate().zfill(2) + 'T' +
        this.getUTCHours().zfill(2) + ':' +
        this.getUTCMinutes().zfill(2) + ':' +
        this.getUTCSeconds().zfill(2) + '.' +
        this.getUTCMilliseconds().zfill(3);
};
...
isoDate()
Date.prototype.isoDate = function() {
  return this.getFullYear() + "-" + (parseInt(this.getMonth())+1) + "-" + this.getDate();
isoDate()
Date.prototype.isoDate = function(){
  var d = this;
  return d.year();
function toJSArray(arr) {
  var len = [arr count],
      res = [];
  while(len--){
    res.push(arr[len]);
...
rfc3339()
function f(n) {
    return n < 10 ? '0' + n : n;
Date.prototype.rfc3339 = function() {
    return this.getUTCFullYear()   + '-' +
         f(this.getUTCMonth() + 1) + '-' +
         f(this.getUTCDate())      + 'T' +
         f(this.getUTCHours())     + ':' +
         f(this.getUTCMinutes())   + ':' +
...