js get the last day of the current month; js get the last day of the previous month; js get on the first day of the current month ago three months

            / * Var = new new myDate a Date ();
            myDate.getYear (); // get the current year (2)
            myDate.getFullYear (); // get the full year (4, 1970 - ????)
            myDate. getMonth (); // get the current month (0-11,0 behalf January)
            myDate.getDate (); // get the current day (1-31)
            myDate.getDay (); // get the current week X (0- 6,0 for Sunday)
            myDate.getTime (); // get the current time (number of milliseconds from the start 1970.1.1)
            myDate.getHours (); // get the current number (0-23) hours
            myDate.getMinutes (); // get the current number (0-59) minutes
            myDate.getSeconds (); // get the current number of seconds (0-59)
            myDate.getMilliseconds (); // get the current milliseconds (0-999)
            myDate.toLocaleDateString () ; // get the current date
            var mytime = myDate.toLocaleTimeString (); // get the current time
            myDate.toLocaleString (); // get the date and time * /
            
            / **
            * Get the current three months before the first day of month
            * /
            function getCurrentMonthThree () {
                var date = new Date (); // current time
                var currentYear = date.getFullYear (); // get the full year
                var currentMonth = date.getMonth (); // current month (0-11,0 behalf January)
                var threeMonth; // first three months of the current month
                var threeMonthFirstDay; three months before the first day of the current month @
                IF (the currentMonth <. 3) {
                    currentYear - = 1; // Save 1 Year
                    threeMonth = currentMonth + 12 - 3; // first three months of the current month
                } the else {
                    threeMonth the currentMonth = -. 3; // first three months of the current month
                }
                threeMonthFirstDay new new = a Date (currentYear, threeMonth,. 1); // three months before the first day of the current month
                return threeMonthFirstDay;
            }
            
            / **
            * Get the current month before the last day of the month
            * /
            function getCurrentMonthOne () {
                var = new new DATE a Date (); // current time
                var currentYear = date.getFullYear (); // get the full year
                var currentMonth = date.getMonth (); // current month (0-11,0 behalf January)
                var oneMonth; // month before the current month
                var oneMonthFirstDay; // month before the first day of the current month
                var monthFirstDay = new Date (currentYear, currentMonth, 1); // first day of the current month
                var oneDay = 1000 * 60 * 60 * 24; // day milliseconds
                oneMonthFirstDay = new Date (monthFirstDay-oneDay ); // first day of the current month minus one day
                return oneMonthFirstDay;
            }
            
            / **
            * Get the last day of the current month
            * /
            function getCurrentMonthLast () {
                var = new new DATE a Date (); // current time
                var currentYear = date.getFullYear (); // get the full year
                var currentMonth = date.getMonth (); // current month (representing January 0-11,0)
                var nextMonth; // the month
                var nextMonthFirstDay; // the first day of the month
                if (currentMonth <11) { // not the last month
                    nextMonth = ++ currentMonth; // add month. 1
                } the else {// the last month
                    currentYear + = 1; // add years. 1
                    nextMonth = 0; // month is the first month
                }
                nextMonthFirstDay = new Date (currentYear, nextMonth, 1 ); // first day of the month
                var oneDay = 1000 * 60 * 60 * 24; // number of milliseconds a day
                return new Date (nextMonthFirstDay-oneDay) ; // first day of the month minus one day
            }

Guess you like

Origin blog.csdn.net/qq_36161345/article/details/92609642