//返回两日期之间相差多少天 function daysBetween(DateOne, DateTwo) { var OneMonth = DateOne.substring(5, DateOne.lastIndexOf('-')); var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf('-') + 1); var OneYear = DateOne.substring(0, DateOne.indexOf('-')); var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf('-')); var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf('-') + 1); var TwoYear = DateTwo.substring(0, DateTwo.indexOf('-')); var cha = ((Date.parse(OneMonth + '/' + OneDay + '/' + OneYear) - Date.parse(TwoMonth + '/' + TwoDay + '/' + TwoYear)) / 86400000); return Math.abs(cha); } //把日期型数据格式化为"yyyy-MM-dd" Date.prototype.format = function(format) // { var o = { "M+": this.getMonth() + 1, //month "d+": this.getDate(), //day "h+": this.getHours(), //hour "m+": this.getMinutes(), //minute "s+": this.getSeconds(), //second "q+": Math.floor((this.getMonth() + 3) / 3), //quarter "S": this.getMilliseconds() //millisecond } if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); return format; }