美文网首页初学前端
JS获取未来月份最小日期(天)和最大日期(天)

JS获取未来月份最小日期(天)和最大日期(天)

作者: 简约酒馆 | 来源:发表于2020-01-02 13:32 被阅读0次

    月份: 0-11       0或12代表1月 从零开始 月份加1得到实际的月份

    星期 :0-6       0代表星期天其他的1-6是正常的

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Title</title>
    </head>
    <body>
    <script>
      let test=new Date(2019,12,31)
      console.log(test.toLocaleString())    //2020/1/31 上午12:00:00
      console.log(test.getDate())     //当月的天数
    
    
      let a=new Date(2019,1,1)     //开始日期
      console.log(a.toLocaleString())   //2019/2/1 上午12:00:00
      console.log(a.getDate())          //开始的日期 (日)
    
    
      let b=new Date(2019,2,0)   //结束日期
      console.log(b.toLocaleString())   //2019/2/28 上午12:00:00
      console.log(b.getDate())   //结束日期    (日)
    </script>
    </body>
    </html>
    

    相关文章

      网友评论

        本文标题:JS获取未来月份最小日期(天)和最大日期(天)

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