1. Determine if a leap year
function Isleapyear (eDate) { var year = edate.getfullyear (); return (((0 = = year% 4) && (0! = (year% 100))) | | (0 = = year%));}
2. Get the total number of days in a month
function Getdaysinmonth (eDate) { var daysinmonth = [31,28,31,30,31,30,31,31,30,31,30,31]; daysinmonth[1] = Isleapyear (eDate)? 29:28; return Daysinmonth[edate.getmonth ()];}
3. Add a few months to the date (if the date you get does not have this day, it will automatically become the last day of the month)
function addmonth (eDate, duration) { var month = Edate.getmonth () + parseint (duration); var day = edate.getdate (); Edate.setdate (1); Edate.setmonth (month); var daysinmonth = getdaysinmonth (eDate); if (Day > daysinmonth) { = daysinmonth; } Edate.setdate (day); return eDate;}
4. Date Modified
function changeexpirydate (expdate, Duration, durationtype) { if(Durationtype = = 2) {//Day expdate.setdate (expdate.getdate () +parseint (duration)); } Else if (Durationtype = = 3) {//Week expdate.setdate (Expdate.getdate () +parseint (duration*7)); } Else if (Durationtype = = 4) {//Month expdate = addmonth (Expdate.gettime (), duration);} }
JS Date processing function--judging leap years, getting the total number of days in the month, adding a month