欢迎光临
我们一直在努力

javascrip计算两个时间差

建站超值云服务器,限时71元/月

javascrip计算两个时间差
<script language="JavaScript">
  //计算天数差的函数,通用   
function DateDiff(starttime,endtime,diff)

 //sDate1和sDate2是2002-12-18格式   
 var sDate1=starttime.value;
 var sDate2=endtime.value;
 var aDate, oDate1, oDate2, iDays   
 aDate = sDate1.split("-")   
 oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) 
 //转换为12-18-2002格式   
 aDate = sDate2.split("-")   
 oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])   
 // alert(oDate1 – oDate2)   
 iDays = parseInt(Math.abs(oDate1 – oDate2) / 1000 / 60 / 60 /24) 
 //把相差的毫秒数转换为天数   
 diff.value=iDays; 

//得当前时间的方法
function getDates(falgs)
{
 var today = new Date();
 var todayStr = today.getYear() + "-";
 if(today.getMonth()<10){
  todayStr = todayStr +"0" +(today.getMonth()+1)+"-";
 }
 else{
  todayStr = todayStr+(today.getMonth()+1)+"-";
 }

 if(today.getDate()<10){
  //alert("11"+today.getDate());
  todayStr = todayStr + "0" +today.getDate();
 }
 else{
  todayStr = todayStr + today.getDate();
 }
 todayStr = todayStr  + "";
 return todayStr;
}
</script>
<html>
<body>
<form name="form1">
开始时间<input type="text" name="createtime">
结束时间<input type="text" name="endtime">
时间差<input type="text" name="diff">
<input type="button" value="确定" onclick="DateDiff(document.all.createtime,document.all.endtime,document.all.diff)">
</form>
</body>
</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » javascrip计算两个时间差
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址