首页 > 编程语言 > 详细

javaScript 获取本周日期

时间:2018-03-22 17:10:40      阅读:222      评论:0      收藏:0      [点我收藏+]

//星期

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 获取本周日期

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!