<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function strToDate(str)
{
var arys= new Array();
arys=str.split('-');
var newDate=new Date(arys[0],parseInt(arys[1], 10) - 1,arys[2]);
return newDate;
}
function days_between(date1,date2){
var ONE_DAY=1000*60*60*24;
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();
var difference_ms = Math.abs(date1_ms- date2_ms);
return Math.round(difference_ms/ONE_DAY);
}
function plus(){
var date1 = strToDate(document.forms[0].date1.value);
var date2 = strToDate(document.forms[0].date2.value);
alert("日期相差天数为:" + days_between(date1,date2));
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>Date1
<input type="text" name="date1" />
</label>
<p>
<label>Date2
<input type="text" name="date2" />
</label>
</p>
<p>
<label>Compute
<input type="submit" name="Submit" value="提交" οnclick="plus()" />
</label>
</p>
</form>
</body>
</html>