## CSDN博客

### 我的工作日志

'例子:GetTimeValue(NOW())
'结果:20041008095752

Function GetTimeValue(DateString)
Dim Temp,TempStr
If isNull(DateString) or isTrueDate(DateString) = 0  Then Exit Function
Temp = csTr(Year(DateString))
If len(temp)<3 Then
Temp = left(year(date),2) & temp
End If
TempStr = Temp

Temp = csTr(month(DateString))
If len(temp)<2 Then Temp = "0" & temp
TempStr = TempStr & Temp

Temp = csTr(day(DateString))
If len(temp)<2 Then Temp = "0" & temp
TempStr = TempStr & Temp

Temp = csTr(Hour(DateString))
If len(temp)<2 Then Temp = "0" & temp
TempStr = TempStr & Temp

Temp = csTr(Minute(DateString))
If len(temp)<2 Then Temp = "0" & temp
TempStr = TempStr & Temp

Temp = csTr(Second(DateString))
If len(temp)<2 Then Temp = "0" & temp
TempStr = TempStr & Temp

GetTimeValue = cCur(TempStr)
End Function
Rem 为VBScript的isDate缺陷而编写的函数,用on error resume next也拦不住
Function isTrueDate(TStr)
Dim T
T = TStr
T = Replace(Replace(Replace(Replace(Replace(Replace(Replace(T,"年","-"),"月","-"),"日"," "),"上午"," "),"下午"," "),"  "," "),"  "," ")

Dim N1,N2
N1 = inStr(T,"-")
If N1>0 Then N2 = inStrRev(T,"-")
If N1 = N2 and N1 >0 Then
isTrueDate = 0
Exit Function
End If

N1 = inStr(T,":")
If N1>0 Then N2 = inStrRev(T,"-")
If N1 = N2 and N1 >0 Then
isTrueDate = 0
Exit Function
End If

If isDate(TStr) Then
isTrueDate = 1
Else
isTrueDate = 0
End If
End Function

0 0