输入小的日期:
1 var aStr = "2015-02-22".split("-"); 2 var aEnd = "2015-03-22".split("-"); 3 4 var arr = [aStr,aEnd]; 5 6 arr.sort(function(a1,a2){ 7 for(var i=0; i<a1.length; i++){ 8 if((a1[i]-a2[i])!=0)return a1[i] - a2[i]; 9 } 10 return 0; 11 }) 12 console.log(arr[0].join("-"));//输出小的日期
朋友告诉我直接比较,
1 var aStr = "2015-02-22".split("-").join(""); 2 var aEnd = "2015-03-22".split("-").join(""); 3 //比较 4 parseInt(aStr)-parseInt(aEnd);
我瞬间感觉白忙活了。。。哭死