function DateAdd (interval,number,date) {/* * functionality: Implements VBScript's DATEADD functionality. * Parameter: Interval, string expression representing the time interval to be added. * Parameter: number, numeric expression that indicates how many time intervals to add. * Parameters: Date, Time object. * Returns: the new Time object. * var now = new Date (); * var newdate = DateAdd ("D", 5,now); *---------------DateAdd (interval,number,date)-----------------*/switch (interval) { Case "Y": {date.setfullyear (Date.getfullyear () +number); return date; Break } case "Q": {Date.setmonth (Date.getmonth () +number*3); return date; Break } case "M": {Date.setmonth (Date.getmonth () +number); return date; Break } case "W" : {date.setdate (Date.getdate () +number*7); return date; Break } case "D": {Date.setdate (Date.getdate () +number); return date; Break } case "H": {date.sethours (date.gethours () +number); return date; Break } case "M": {date.setminutes (Date.getminutes () +number); return date; Break } case "S": {date.setseconds (Date.getseconds () +number); return date; Break } default: {date.SetDate (D.getdate () +number); return date; Break }}} var now = new Date (); Plus five days. var newdate = DateAdd ("D", 5,now); Alert (newdate.tolocaledatestring ())//plus two months. Newdate = DateAdd ("M", 2,now); Alert (newdate.tolocaledatestring ())//plus one year newdate = DateAdd ("y", 1,now); Alert (newdate.tolocaledatestring ())
JS calculates the specified date plus how many days, plus how many months, plus how many years of the date