码迷,mamicode.com
首页 > 编程语言 > 详细

javaScript 获取本周日期

时间:2018-03-22 17:20:28      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:new   set   cti   let   script   rip   func   设置   post   

//星期

function formatWeek(n){
      let myDate = new Date();
      let theDay=myDate.getDay()
      let week=[‘星期一‘,‘星期二‘,‘星期三‘,‘星期四‘,‘星期五‘,‘星期六‘,‘星期日‘]
      let year=myDate.getFullYear();
      let month=myDate.getMonth()+1;
      let day=myDate.getDate();
      return week[n]
}

//日期

function formatDay(AddDayCount) {
      let myDate = new Date();
      myDate.setDate(myDate.getDate()+AddDayCount);//设置当前日期加几天(减几天)
      let y = myDate.getFullYear();
      let m = myDate.getMonth()+1;
      let d = myDate.getDate();
      return y+"年"+m+"月"+d+"日";
}

for(let i=0;i<7;i++){
      let myDate = new Date();
      let theDay=myDate.getDay()
      if(i<theDay){
               if(i==theDay-1){
                        document.write(formatDay(i-(theDay-1))+‘今天‘+‘............‘)
               }else{
                        document.write(formatDay(i-(theDay-1))+formatWeek(i)+‘............‘)
               }
        }else {
                document.write(formatDay(i-(theDay-1))+formatWeek(i)+‘............‘)
        }
}

javaScript 获取本周日期

标签:new   set   cti   let   script   rip   func   设置   post   

原文地址:https://www.cnblogs.com/hellowoeld/p/8624479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!