'返回时间格式:2012-03-08
Function DateTimeFormat(dateTime)
reStr = ""
reStr = Year(dateTime) & "-"
If Len(Month(dateTime))=1 Then
reStr = reStr & "0" & Month(dateTime) & "-"
Else
reStr = reStr & Month(dateTime) & "-"
End If
If Len(Day(dateTime))=1 Then
reStr = reStr & "0" & Day(dateTime)
Else
reStr = reStr & Day(dateTime)
End If
DateTimeFormat = reStr
End Function
'过滤所有的 HTML 标记
Function NoHTML(strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>"
Set Matches = objRegExp.Execute(strHTML)
'遍历匹配集合,并替换掉匹配的项
For Each Match in Matches
strHtml=Replace(strHTML,Match.Value,"")
Next
NoHTML = strHTML
Set objRegExp = Nothing
End Function
'返回指定长度的字符串,长度按字节算,汉字算两个(GB2312编码和UTF-8编码有不同)
'Asc返回字符的代码,值范围为0到255。AscW返回字符的Unicode代码,值范围为0到65535
Function CutStr(str, strLen)
Dim l,t,c,i
If IsNull(str) Then CutStr="":Exit Function
l = Len(str)
strLen = Int(strLen)
t=0
For i=1 To l
c = AscW(Mid(str,i,1)) 'GB2312编码使用 Asc 函数。UTF-8编码使用 AscW 函数
If c >= 0 And c <= 255 Then
t = t + 1
Else
t = t + 2
End If
IF t>strLen Then
CutStr = Left(str, i-1)
Exit For
Else
CutStr = str
End If
Next
End Function
'返回指定月的天数
Function GetMonthCountDay(yearNum, monthNum)
Dim date1,date2
If Int(monthNum)<12 Then
date1 = DateSerial(yearNum, monthNum, 1)
date2 = DateSerial(yearNum, monthNum + 1, 1)
GetMonthCountDay = DateDiff("d", date1, date2)
ElseIf Int(monthNum)=12 Then
GetMonthCountDay = 31
Else
monthNum = monthNum - 12
date1 = DateSerial(yearNum+1, monthNum, 1)
date2 = DateSerial(yearNum+1, monthNum + 1, 1)
GetMonthCountDay = DateDiff("d", date1, date2)
End If
End Function
'返回指定范围内的随机数字
Function RndNumber(MaxNum, MinNum)
Randomize
RndNumber = Int((MaxNum - MinNum + 1) * Rnd + MinNum)
RndNumber = RndNumber
End Function
'GB2312编码
'Server.UrlEncode(str)
'Server.UrlDecode(str) 这个函数不存在
Function UrlDecodeGB2312(sIn)
Dim s,i,l,c,t,n : s="" : l=Len(sIn)
For i=1 To l
c=Mid(sIn,i,1)
If c<>"%" Then
s = s & c
Else
c=Mid(sIn,i+1,2) : i=i+2 : t=CInt("&H" & c)
If t<&H80 Then
s=s & Chr(t)
Else
c=Mid(sIn,i+1,3)
If Left(c,1)<>"%" Then
UrlDecodeGB2312=s
Exit Function
Else
c=Right(c,2) : n=CInt("&H" & c)
t=t*256+n-65536
s = s & Chr(t) : i=i+3
End If
End If
End If
Next
UrlDecodeGB2312=s
End Function



