llgd.net
当前位置:首页 >> JS 计算两个日期之间相差多少天 >>

JS 计算两个日期之间相差多少天

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(...

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) } 参数是时间格式;只取天数,不满一天不算

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

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...

转为 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 time = date2.getTime() - date1.getTime() ; //日期的long型值之差 两个日期相差 Math.floor(time/(24*60*60*1000)) 天

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(getTi...

var start = $("#startDate").val();var end = $("#endDate").val();var date1 = new Date(start.replace(/[^\/\d]+/g,"/")+",0:0:0");var date2 = new Date(end.replace(/[^\/\d]+/g,"/")+",0:0:0");date1.setMonth(date1.getMonth() + 2);if (...

//+--------------------------------------------------- //| 求两个时间的天数差 日期格式为 YYYY-MM-dd //+--------------------------------------------------- function daysBetween(DateOne,DateTwo) { var OneMonth = DateOne.substring...

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));

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