Convert a serial YYYYMMDD string to a date, convert a date to serial YYYYMMDD format - Node.js Date

Node.js examples for Date:Date Format

Description

Convert a serial YYYYMMDD string to a date, convert a date to serial YYYYMMDD format

Demo Code

String.prototype.SerialToDate = function() {
  var d = String(this);
  d = d.Trim();//w w w.  j a v a 2 s  . co  m
  var date = (d.length >= 8 ? new Date(d.substr(0,4).toInt(), d.substr(4,2).toInt() - 1, d.substr(6,2).toInt()) : new Date());
  return date;
}

Date.prototype.DateToSerial = function() {
  return String(this.getFullYear()).Pad(4,"0")+String(this.getMonth()+1).Pad(2,"0")+String(this.getDate()).Pad(2,"0");
}

Related Tutorials