js时间日期比较
1 <script type="text/javascript"> 2 //begin > end 返回True 3 function comptime(beginTime, endTime) { 4 var begin = beginTime.replace(new RegExp("/", "g"), '-'); 5 var end = endTime.replace(new RegExp("/", "g"), '-'); 6 var beginDate = begin.split(" ")[0]; 7 var endDate = end.split(" ")[0]; 8 9 var beginTime = begin.split(" ").length == 1 ? new Array() : begin.split(" ")[1].split(":"); 10 var endTime = end.split(" ").length == 1 ? new Array() : end.split(" ")[1].split(":"); 11 12 if (new Date(beginDate) > new Date(endDate)) { 13 return true; 14 } 15 if (new Date(beginDate) < new Date(endDate)) { 16 return false; 17 }else { 18 var length = beginTime.length > endTime.length ? beginTime.length : endTime.length; 19 beginTime = beginTime.padding(0,length); 20 endTime = endTime.padding(0, length); 21 for (var i = 0; i < length; i++) { 22 if (parseInt(beginTime[i], 10) > parseInt(endTime[i], 10)) { 23 return true; 24 } 25 } 26 return false; 27 } 28 } 29 30 Array.prototype.padding = function (numchar, length) { 31 if (this.length < length) { 32 for (var i = 0; i < length - this.length; i++) { 33 this.push(numchar); 34 } 35 } 36 37 return this; 38 } 39 </script>