读书人

js 累加日期以及追加小时

发布时间: 2012-09-29 10:30:01 作者: rapoo

js 追加日期以及追加小时

//追加日期 function addDay(dates,num) {     var   d=new   Date(dates.replace(/-/g,"/"));     d.setDate(d.getDate()+num);     var tempday=d.getDate();    var tempmonth=(1+d.getMonth());    if(tempday.toString().length==1)        tempday="0"+tempday;    if(tempmonth.toString().length==1)        tempmonth="0"+tempmonth;    return   d.getFullYear()+ "-"+tempmonth+ "-"+tempday;  }  //追加小时 function addHour(dates,num) {     var   d=new   Date(dates.replace(/-/g,"/"));     d.setHours(d.getHours()+num);     var tempday=d.getDate();    var tempmonth=(1+d.getMonth());    var temphour=d.getHours();    var tempmin=d.getMinutes();    if(tempday.toString().length==1)        tempday="0"+tempday;    if(tempmonth.toString().length==1)        tempmonth="0"+tempmonth;    if(temphour.toString().length==1)        temphour="0"+temphour;    if(tempmin.toString().length==1)        tempmin="0"+tempmin;     return   d.getFullYear()+ "-"+tempmonth+ "-"+tempday+" "+temphour+":"+tempmin;  }
?

读书人网 >JavaScript

热点推荐