js获取当前月的最后一天;js获取上个月的最后一天;js获取当前月前三个月的第一天

            /* var myDate = new Date();
            myDate.getYear();        //获取当前年份(2位)
            myDate.getFullYear();    //获取完整的年份(4位,1970-????)
            myDate.getMonth();       //获取当前月份(0-11,0代表1月)
            myDate.getDate();        //获取当前日(1-31)
            myDate.getDay();         //获取当前星期X(0-6,0代表星期天)
            myDate.getTime();        //获取当前时间(从1970.1.1开始的毫秒数)
            myDate.getHours();       //获取当前小时数(0-23)
            myDate.getMinutes();     //获取当前分钟数(0-59)
            myDate.getSeconds();     //获取当前秒数(0-59)
            myDate.getMilliseconds();    //获取当前毫秒数(0-999)
            myDate.toLocaleDateString();     //获取当前日期
            var mytime=myDate.toLocaleTimeString();     //获取当前时间
            myDate.toLocaleString( );        //获取日期与时间 */
            
            /**
            *    获取当前月前三个月的第一天
            */
            function getCurrentMonthThree(){
                var date=new Date();                //当前时间
                var currentYear=date.getFullYear();    //获取完整的年份
                var currentMonth=date.getMonth();    //当前月份(0-11,0代表1月)
                var threeMonth;                        //当前月的前三个月
                var threeMonthFirstDay;                //当前月的前三个月的第一天
                if(currentMonth < 3){
                    currentYear -= 1;                    //年份减1
                    threeMonth = currentMonth + 12 - 3;    //当前月的前三个月
                } else {
                    threeMonth = currentMonth - 3;    //当前月的前三个月
                }
                threeMonthFirstDay = new Date(currentYear,threeMonth,1);    //当前月的前三个月的第一天
                return threeMonthFirstDay;
            }
            
            /**
            *    获取当前月前一个月的最后一天
            */
            function getCurrentMonthOne(){
                var date=new Date();                //当前时间
                var currentYear=date.getFullYear();    //获取完整的年份
                var currentMonth=date.getMonth();    //当前月份(0-11,0代表1月)
                var oneMonth;                        //当前月的前一个月
                var oneMonthFirstDay;                //当前月的前一个月的第一天
                var monthFirstDay = new Date(currentYear,currentMonth,1);    //当前月的第一天
                var oneDay=1000*60*60*24;                                    //一天的毫秒数
                oneMonthFirstDay =  new Date(monthFirstDay-oneDay);        //当前月的第一天减去一天
                return oneMonthFirstDay;
            }
            
            /**
            *    获取当前月的最后一天
            */
            function getCurrentMonthLast(){
                var date=new Date();                //当前时间
                var currentYear=date.getFullYear();    //获取完整的年份
                var currentMonth=date.getMonth();    //当前月份(0-11,0代表1月)
                var nextMonth;                        //下一个月
                var nextMonthFirstDay;                //下一个月的第一天
                if(currentMonth < 11){                //不是最后一个月
                    nextMonth=++currentMonth;        //月份加1
                } else {                            //最后一个月
                    currentYear += 1;                //年加1
                    nextMonth = 0;                    //月份为第一个月
                }
                nextMonthFirstDay=new Date(currentYear,nextMonth,1);    //下一个月的第一天
                var oneDay=1000*60*60*24;                                //一天的毫秒数
                return new Date(nextMonthFirstDay-oneDay);                //下一个月的第一天减去一天
            }

猜你喜欢

转载自blog.csdn.net/qq_36161345/article/details/92609642