js获取当前时间往后加6天
获取当前时间往后加6天,并绑定星期几(星期几是最笨的的方法,一个一个判读),后期在优化
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> function GetDateStr(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期 var y = dd.getFullYear(); var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);//获取当前月份的日期,不足10补0 var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();//获取当前几号,不足10补0 //return y+"-"+m+"-"+d;年月日 return m+"-"+d; } var xqj= new Date(GetDateStr(0)); if(xqj.getDay()==0){ console.log('星期日'+GetDateStr(0)) }else if(xqj.getDay()==1){ console.log('星期一'+GetDateStr(0)) }else if(xqj.getDay()==2){ console.log('星期二'+GetDateStr(0)) }else if(xqj.getDay()==3){ console.log('星期三'+GetDateStr(0)) }else if(xqj.getDay()==4){ console.log('星期四'+GetDateStr(0)) }else if(xqj.getDay()==5){ console.log('星期五'+GetDateStr(0)) }else if(xqj.getDay()==6){ console.log('星期六'+GetDateStr(0)) } /* var myDate = new Date(); myDate.getMonth(); //获取当前月份(0-11,0代表1月) myDate.getDate(); //获取当前日(1-31) * */ /*console.log(+'---'+GetDateStr(0)) console.log(new Date(GetDateStr(1)).getDay()+'---'+GetDateStr(1)) console.log(new Date(GetDateStr(2)).getDay()+'---'+GetDateStr(2)) console.log(new Date(GetDateStr(3)).getDay()+'---'+GetDateStr(3)) console.log(new Date(GetDateStr(4)).getDay()+'---'+GetDateStr(4)) console.log(new Date(GetDateStr(5)).getDay()+'---'+GetDateStr(5))*/ </script> </body> </html>