knrt.net
当前位置:首页 >> js得到两个日期之间有多少天 >>

js得到两个日期之间有多少天

将两个日期转换成毫秒,然后相减,再计算出天数 var date1 = new Date('2016/12/31').getTime(), date2 = new Date().getTime(); var diff = date2 - date1; //相差的毫秒数 var day = diff / 1000; //相差秒数 day = day / 60; //相差分钟数 da...

function compare(start,end){ start =start.getTime(); end =end.getTime(); var time =0 if(start>end){ time =start-end; }else{ time =end-start; } return Math.floor(time/86400000) } 参数是时间格式;只取天数,不满一天不算

function getTime2Time($time1, $time2){var time1 = arguments[0], time2 = arguments[1];time1 = Date.parse(time1)/1000;time2 = Date.parse(time2)/1000;var time_ = time1 - time2;return (time_/(3600*24));}document.write(getTime2Time(...

var time = date2.getTime() - date1.getTime() ; //日期的long型值之差 两个日期相差 Math.floor(time/(24*60*60*1000)) 天

转为 DATE() 类型 直接相减 得出毫秒数 除1000 得秒数 除60000 得分钟数 var d1 = new Date('2016/03/28 10:17:22');var d2 = new Date('2016/03/28 11:17:22');console.log(parseInt(d2 - d1));//两个时间相差的毫秒数console.log(parseInt(d2 ...

var days = daysBetween('2016-11-01','2016-11-02'); /** * 根据两个日期,判断相差天数 * @param sDate1 开始日期 如:2016-11-01 * @param sDate2 结束日期 如:2016-11-02 * @returns {number} 返回相差天数 */ function daysBetween(sDate1...

1.把开始时间和结束时间保存 var dateFrom = new Date(strFrom); var dateTo = new Date(strTo); 2.计算时间差 var diff = dateTo.valueOf() - dateFrom.valueOf(); 3.时间差转换为天数 var diff_day = parseInt(diff/(1000*60*60*24));

var date1 = new Date('2013/04/02 18:00')var date2 = new Date('2013/04/02 19:22:21')var s1 = date1.getTime(),s2 = date2.getTime();var total = (s2 - s1)/1000;var day = parseInt(total / (24*60*60));//计算整数天数var afterDay = tot...

//起始日期也在计算范围内function getRestDays(bd,ed){ var d1=new Date(bd),d2=new Date(ed); var dateSpan=d2-d1; var days=parseInt(dateSpan/(24*3600*1000))+1;//计算两个日期间的天数差,加1是为了把起始日期计算在内 var weeks=parseInt...

function diy_time(time1,time2){ time1 = Date.parse(new Date(time1)); time2 = Date.parse(new Date(time2)); return time3 = '相差'+Math.abs(parseInt((time2 - time1)/1000/3600*7))+'星期'; } var time1 = "2017-01-01 01:00:00"; var t...

网站首页 | 网站地图
All rights reserved Powered by www.knrt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com