Date.monthNames = [
    'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
    'November', 'December', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
];
Date.prototype.monthNames = Date.monthNames;
Date.dayNames = [
    'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
    'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
];
Date.prototype.dayNames = Date.dayNames;
Date.daysInMonth = [ 31,28,31,30,31,30,31,31,30,31,30,31 ];
Date.prototype.daysInMonth = Date.daysInMonth;
Date.isLeapYear = function(year) {
  year = parseInt(year);
  if (year%4 == 0) {
    if (year%100 != 0) {
        return true;
    }
    else {
        return (year%400 == 0);
    }
  }
  return false;
};
Date.prototype.isLeapYear = function() {
  var year = this.getFullYear();
  if (year%4 === 0) {
    if (year%100 !== 0) {
        return true;
    }
    else {
        return (year%400 === 0);
    }
  }
  return false;
};
Date.prototype.format = function(format) {
    function LZ(x) {return(x<0||x>9?"":"0")+x}
	format=format+"";
	var result="", i_format=0, c="", token="";
	var y=this.getYear()+"", M=this.getMonth()+1, d=this.getDate(), E=this.getDay();
	var H=this.getHours(), m=this.getMinutes(), s=this.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value={};
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y; value["yyyy"]=y; value["yy"]=y.substring(2,4);
	value["M"]=M; value["MM"]=LZ(M); value["MMM"]=this.monthNames[M-1]; value["NNN"]=this.dayNames[M+11];
	value["d"]=d; value["dd"]=LZ(d); value["E"]=this.dayNames[E+7]; value["EE"]=this.dayNames[E];
	value["H"]=H; value["HH"]=LZ(H);
	if (H==0){value["h"]=12;} else if (H>12){value["h"]=H-12;} else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1; value["KK"]=LZ(value["K"]); value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; } else { value["a"]="AM"; }
	value["m"]=m; value["mm"]=LZ(m); value["s"]=s; value["ss"]=LZ(s);
    while (i_format < format.length) {
		c=format.charAt(i_format); token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
            token += format.charAt(i_format++);
		}
		if (value[token] != null) { result=result + value[token]; } else { result=result + token; } 
	}
	return result;
}

