计算两个日期相差的天数
2009-07-03 11:09
260 查看
<!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="提交" onclick="plus()" />
</label>
</p>
</form>
</body>
</html>
<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="提交" onclick="plus()" />
</label>
</p>
</form>
</body>
</html>
相关文章推荐
- JS 计算两个日期相差天数
- php计算两个日期的相差天数,处理时间间隔
- javaScript 计算两个日期的天数相差(示例代码)
- 计算两个日期之间相差的天数(带带负数) 支持格式YYYY-mm-dd和YYYY-mm-dd HH:mm:ss
- 分享PHP计算两个日期相差天数的代码
- 计算两个日期相差的天数
- 如何计算两个日期之间相差天数
- java计算两个字符串日期相差的天数
- JavaScript计算两个日期之间相差的天数
- Java 计算两个日期相差的天数
- Calendar:计算两个日期相差的天数
- 计算两个字符串日期相差的天数
- MSSQL计算两个日期相差的工作天数
- Java 计算两个日期相差的天数
- java计算两个日期之间相差的天数
- java计算两个日期之间相差的天数
- java计算两个日期之间相差的天数
- C#中如何获得两个日期之间的天数差 ( c# 计算两个日期之间相差的天数 )
- Java计算两个具体日期相差的天数
- 计算两个日期之间相差的天数