Function 标准日期(ByValstr$)AsDateDim pat$, result$
arr =Array("(\d{4}).*?(\d{1,2}).*?(\d{1,2})","(\d{4}).*?(\d{1}).*?(\d{1,2})")IfLen(str)<8Then pat = arr(1)Else pat = arr(0)With CreateObject("vbscript.regexp")'正则表达式
.Global=True
.Pattern = pat
result = .Replace(str,"$1/$2/$3")EndWith
标准日期 = Format(result,"yyyy/mm/dd")EndFunction
1
2
3
4
5
6
7
8
9
10
11
标准日期时间提取
Function 标准日期时间(ByValstr$)AsDateDim pat$, res$, result$, t&On ErrorResumeNext
pat ="(\d{4}).*?(\d{1,2}).*?(\d{1,2}).*?(\d{1,2}).*?(\d{1,2}).*?(\d{1,2}).*"
res ="$1/$2/$3 $4:$5:$6"With CreateObject("vbscript.regexp")'正则表达式
.Global=True
.Pattern = pat
Do
result = .Replace(str, res): t =CLng(Mid(result,1,4))IfCDate(result)="0:00:00"Or t <1900Thenstr=Mid(str,2)ElseExitDoIfLen(str)<6Then result ="#Error":ExitDo'没有日期LoopWhileLen(str)>1EndWith
标准日期时间 = Format(result,"yyyy/mm/dd hh:mm:ss")EndFunction