Javascript Date yyyymmdd(separator)

Description

Javascript Date yyyymmdd(separator)

// http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object
Date.prototype.yyyymmdd = function(separator) {
  var separator = separator || "";
  var mm = this.getMonth() + 1; // getMonth() is zero-based
  var dd = this.getDate();

  return [this.getFullYear(),
          (mm>9 ? '' : '0') + mm,
          (dd>9 ? '' : '0') + dd
         ].join(separator);/*ww w .jav  a 2 s  .  c  o  m*/
};



PreviousNext

Related