javascript中string类型转为date类型,然后比较

  <SCRIPT LANGUAGE="JavaScript">
//execScript('n = DateDiff("d","2003-01-01","2003-01-02")');

//document.write(n);
var s="2003-01-01";
var s2="2003-01-03";
var date=new Date(Date.parse(s.replace(/-/g, "/")));
var date2=new Date(Date.parse(s2.replace(/-/g, "/")));
var str=date2.getTime()-date.getTime();
var sr=str/(24*3600*1000);
//alert(39*365*24*3600*1000);

alert(sr);
  </SCRIPT>

你可能感兴趣的:(JavaScript)