欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js获取月初月末

程序员文章站 2022-03-03 09:06:29
...
    <script>
        var time = new Date();
        var timeYear = time.getFullYear();
        var timeMonth = time.getMonth()+1;
        if(timeMonth>12){
            timeMonth = 1;
            y++
        }
        var monthLastDay = new Date(timeYear,timeMonth,0).getDate(); //当前月月末日
        var yc = timeYear+"-"+(timeMonth<10?"0"+timeMonth:timeMonth)+"-"+"01"+" 00:00:00";
        var ym = timeYear+"-"+(timeMonth<10?"0"+timeMonth:timeMonth)+"-"+(monthLastDay<10?"0"+monthLastDay:monthLastDay)+" 23:59:59";
        console.log("月初=>",yc)
        console.log("月末=>",ym)
    </script>
相关标签: js方法 javascript