VBScript DateAdd 函数
一个函数,返回已添加指定时间间隔的日期。
语法
DateAdd(interval,number,date)
参数说明
interval,必需参数。 它可以取以下值 −
d − day of the year.
m − month of the year
y − year of the year
yyyy − year
w − weekday
ww − week
q − quarter
h − hour
m − minute
s − second
number,必填参数。 它可以采用正参数和负参数。
date,必填参数。 表示添加间隔的日期的变体或文字。
示例
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> ' Positive Interal date1 = 01-Jan-2013 document.write("Line 1 : " &DateAdd("yyyy",1,date1) & "<br />") document.write("Line 2 : " &DateAdd("q",1,date1) & "<br />") document.write("Line 3 : " &DateAdd("m",1,date1) & "<br />") document.write("Line 4 : " &DateAdd("y",1,date1) & "<br />") document.write("Line 5 : " &DateAdd("d",1,date1) & "<br />") document.write("Line 6 : " &DateAdd("w",1,date1) & "<br />") document.write("Line 7 : " &DateAdd("ww",1,date1) & "<br />") document.write("Line 8 : " &DateAdd("h",1,"01-Jan-2013 12:00:00") & "<br />") document.write("Line 9 : " &DateAdd("n",1,"01-Jan-2013 12:00:00") & "<br />") document.write("Line 10 : "&DateAdd("s",1,"01-Jan-2013 12:00:00") & "<br />") ' Negative Interval document.write("Line 11 : " &DateAdd("yyyy",-1,date1) & "<br />") document.write("Line 12 : " &DateAdd("q",-1,date1) & "<br />") document.write("Line 13 : " &DateAdd("m",-1,date1) & "<br />") document.write("Line 14 : " &DateAdd("y",-1,date1) & "<br />") document.write("Line 15 : " &DateAdd("d",-1,date1) & "<br />") document.write("Line 16 : " &DateAdd("w",-1,date1) & "<br />") document.write("Line 17 : " &DateAdd("ww",-1,date1) & "<br />") document.write("Line 18 : " &DateAdd("h",-1,"01-Jan-2013 12:00:00") & "<br />") document.write("Line 19 : " &DateAdd("n",-1,"01-Jan-2013 12:00:00") & "<br />") document.write("Line 20 : " &DateAdd("s",-1,"01-Jan-2013 12:00:00") & "<br />") </script> </body> </html>
当您将其另存为 .html 并在 Internet Explorer 中执行时,上述脚本将产生以下结果 −
Line 1 : 27/06/1895 Line 2 : 27/09/1894 Line 3 : 27/07/1894 Line 4 : 28/06/1894 Line 5 : 28/06/1894 Line 6 : 28/06/1894 Line 7 : 4/07/1894 Line 8 : 1/01/2013 1:00:00 PM Line 9 : 1/01/2013 12:01:00 PM Line 10 : 1/01/2013 12:00:01 PM Line 11 : 27/06/1893 Line 12 : 27/03/1894 Line 13 : 27/05/1894 Line 14 : 26/06/1894 Line 15 : 26/06/1894 Line 16 : 26/06/1894 Line 17 : 20/06/1894 Line 18 : 1/01/2013 11:00:00 AM Line 19 : 1/01/2013 11:59:00 AM Line 20 : 1/01/2013 11:59:59 AM