首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js 累加日期以及追加小时

2012-09-29 
js 追加日期以及追加小时//追加日期 function addDay(dates,num) {vardnewDate(dates.replace(/-/g,/))

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;  }
?

热点排行