<Script> Function DateAdd (interval, number, date) { /* * --------------- DateAdd (interval, number, date )----------------- * DateAdd (interval, number, date) * Function: implements the DateAdd function of VBScript. * Parameter: interval, a string expression, indicating the time interval to be added. * Parameter: number, numeric expression, indicating the number of time intervals to be added. * Parameter: date, time object. * Return: a new time object. * Var now = new Date (); * Var newDate = DateAdd ("d", 5, now ); * Author: wanghr100 (Baby gray bean. net) * Update: * --------------- 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 (); // Add five days. Var newDate = DateAdd ("d", 5, now ); Alert (newDate. toLocaleDateString ()) // Add two months. NewDate = DateAdd ("m", 2, now ); Alert (newDate. toLocaleDateString ()) // Add one year NewDate = DateAdd ("y", 1, now ); Alert (newDate. toLocaleDateString ()) </Script> |