幾種常用VB.NET時間函數介紹
對于VB.NET中的函數,在學習的過程中需要從各個方面去進行日常的經驗積累,才能方便我們日后使用。在這里就先為大家介紹兩種常用的VB.NET時間函數,方便大家參考學習,增加自己對VB.NET編程的理解。#t#
VB.NET時間函數之函數Dateadd()
功能:計算某個指定的時間和
格式: dateadd(timeinterval,number,date)
參數:timeinterval是時間單位(月,日..); number是時間間隔值,date是時間始點.
例子:
- < %
- currentDate = #8/4/99#
- newDate = DateAdd
(“m”,3,currentDate)- response.write newDate
- %>
- < %currentDate =
#12:34:45 PM#- newDate = DateAdd
(“h”,3,currentDate)- response.write newDate
- %>
結果:
11/4/99
3:34:45 PM
其中
“m” = ”month”;
“d” = ”day”;
如果是currentDate 格式,則,
“h” = ”hour”;
“s” = ”second”;
VB.NET時間函數之函數Datediff()
功能:計算某量個指定的時間差
格式: datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])
參數: timeinterval 是時間單位; date1,date2是有效的日期表達式,firstdayofweek,firstdayofyear 是任意選項.
例子:
- < %fromDate = #8/4/99#
- toDate = #1/1/2000#
- response.write ”There
are ” & _- DateDiff(“d”,fromDate,
toDate) & _- “ days to millenium
from 8/4/99.”- %>
結果:There are 150 days to millenium from 8/4/99.