方法一this
function compareDate1(){ var str1 ="2015-07-22",str2 = "2015-07-26"; var arr1 = str1 .split("-"); var arr2 = str2 .split("-"); var date1=new Date(parseInt(arr1[0]),parseInt(arr1[1])-1,parseInt(arr1[2]),0,0,0); var date2=new Date(parseInt(arr2[0]),parseInt(arr2[1])-1,parseInt(arr2[2]),0,0,0); console.log(date1+""+date2); if(date1.getTime()>date2.getTime()){ alert('結束日期不能小於開始日期',this); return null; } }
方法二code
function CompareDate2(param1,param2) { return ((new Date(param1.replace(/-/g,"\/"))) > (new Date(param2.replace(/-/g,"\/")))); }
方法三get
function CompareDate3(){ DateTime a = DateTime.parse("2010-1-9 8:00:00"); DateTime b = DateTime.parse("2010-1-13 13:41:52"); return a > b; }