functionDateAdd (interval, number, date) {/** Function: Realize the DATEADD function of JSScript. * 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 ); returndate; Break; } Case"Q": {date.setmonth (Date.getmonth ()+ Number * 3); returndate; Break; } Case"M": {date.setmonth (Date.getmonth ()+Number ); returndate; Break; } Case"W": {date.setdate (date.getdate ()+ Number * 7); returndate; Break; } Case"D": {date.setdate (date.getdate ()+Number ); returndate; Break; } Case"H": {date.sethours (date.gethours ()+Number ); returndate; Break; } Case"M": {date.setminutes (date.getminutes ()+Number ); returndate; Break; } Case"S": {date.setseconds (Date.getseconds ()+Number ); returndate; Break; } default: {date.setdate (d.getdate ()+Number ); returndate; Break; } } } //called varNewdate = DateAdd ("Y", 1, dtadate);
Turn: Http://blog.163.com/[email protected]/blog/static/13393333720141066026886/
JS implementation date information to increase the number of years, months, days