獲取當前時間往后加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>
