對(duì)于VB.NET中的函數(shù),在學(xué)習(xí)的過(guò)程中需要從各個(gè)方面去進(jìn)行日常的經(jīng)驗(yàn)積累,才能方便我們?nèi)蘸笫褂?。在這里就先為大家介紹兩種常用的VB.NET時(shí)間函數(shù),方便大家參考學(xué)習(xí),增加自己對(duì)VB.NET編程的理解。
VB.NET時(shí)間函數(shù)之函數(shù)Dateadd()
功能:計(jì)算某個(gè)指定的時(shí)間和
格式: dateadd(timeinterval,number,date)
參數(shù):timeinterval是時(shí)間單位(月,日..); number是時(shí)間間隔值,date是時(shí)間始點(diǎn).
例子:
- < %
- 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
- %>
結(jié)果:
11/4/99
3:34:45 PM
其中
“m” = ”month”;
“d” = ”day”;
如果是currentDate 格式,則,
“h” = ”hour”;
“s” = ”second”;
VB.NET時(shí)間函數(shù)之函數(shù)Datediff()
功能:計(jì)算某量個(gè)指定的時(shí)間差
格式: datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])
參數(shù): timeinterval 是時(shí)間單位; date1,date2是有效的日期表達(dá)式,firstdayofweek,firstdayofyear 是任意選項(xiàng).
例子:
- < %fromDate = #8/4/99#
- toDate = #1/1/2000#
- response.write ”There
are ” & _- DateDiff(“d”,fromDate,
toDate) & _- “ days to millenium
from 8/4/99.”- %>
結(jié)果:There are 150 days to millenium from 8/4/99.
聯(lián)系客服