美文网首页
js获取当前的年月日和一周前的年月日

js获取当前的年月日和一周前的年月日

作者: tangzhentian | 来源:发表于2021-10-28 10:01 被阅读0次
          //现在的时间
          var dates = new Date();
          let year = dates.getFullYear();
          let mounth = (dates.getMonth() + 1).toString().padStart(2,'0');
          let day = dates.getDate().toString().padStart(2,'0');
          let hour = dates.getHours().toString().padStart(2,'0');
          let minutes = dates.getMinutes().toString().padStart(2,'0');
          // 2021-10-28 09:57
          console.log(year+'-'+mounth+'-'+day+' '+hour+':'+minutes);
          // 一周前的时间
          var time=(new Date()).getTime()-7*24*60*60*1000;
          var tragetTime=new Date(time);
          let tyear = tragetTime.getFullYear();
          let tmounth = (tragetTime.getMonth() + 1).toString().padStart(2,'0');
          let tday = tragetTime.getDate().toString().padStart(2,'0');
          let thour = tragetTime.getHours().toString().padStart(2,'0');
          let tminutes = tragetTime.getMinutes().toString().padStart(2,'0');
          // 2021-10-21 09:57
          console.log(tyear+'-'+tmounth+'-'+tday+' '+thour+':'+tminutes);
    

    相关文章

      网友评论

          本文标题:js获取当前的年月日和一周前的年月日

          本文链接:https://www.haomeiwen.com/subject/nqamaltx.html