码迷,mamicode.com
首页 > Web开发 > 详细

js根据2个日期计算相差天数

时间:2015-11-09 12:37:42      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

 1 function getDays(strDateStart,strDateEnd){
 2    var strSeparator = "-"; //日期分隔符
 3    var oDate1;
 4    var oDate2;
 5    var iDays;
 6    oDate1= strDateStart.split(strSeparator);
 7    oDate2= strDateEnd.split(strSeparator);
 8  var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
 9   var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
10    iDays = parseInt(Math.abs(strDateS - strDateE ) / 1000 / 60 / 60 /24)//把相差的毫秒数转换为天数 
11    return iDays ;
12 }

 

js根据2个日期计算相差天数

标签:

原文地址:http://www.cnblogs.com/nwme/p/4949362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!