JS获取当月第一天和最后一天

    // 把日期格式转换成时间撮       

    var time = new Date().getTime();

        console.log(getCurrentMonthFirst());

       console.log(getCurrentMonthLast());

     // 获取当前月的第一天

        function getCurrentMonthFirst(){
            var date=new Date();
            date.setDate(1);
            return date;
        }
        // 获取当前月的最后一天
        function getCurrentMonthLast(){
            var date=new Date();
            var currentMonth=date.getMonth();
            var nextMonth=++currentMonth;
            var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
            var oneDay=1000*60*60*24;
            return new Date(nextMonthFirstDay-oneDay);

        }

借鉴:https://blog.csdn.net/cathylou/article/details/51759426

猜你喜欢

转载自blog.csdn.net/web_cgh/article/details/80049926