function Days() { //开始时间 var txtYearAnnualDates =txtBeginTime.GetText(); //结束时间 var txtNextYearAnnualDates = txtEndSendTime.GetText(); //转为时间 var YearAnnualDates = new Date(txtYearAnnualDates.replace(/-/g, "/")); var NextYearAnnualDates = new Date(txtNextYearAnnualDates.replace(/-/g, "/"));//转换成Data();
//var month=date.getMonth()+1; //获取当前月份
//两数相减得出天数 var days = (Math.abs(NextYearAnnualDates - YearAnnualDates)) / 1000 / 60 / 60 / 24; alert(days);//7 }
js中单独调用new Date(),例如document.write(new Date());
显示的结果是:Mar 31 10:10:43 UTC+0800 2012 这种格式的时间
但是用new Date() 参与计算会自动转换为从1970.1.1开始的毫秒数