再继续复杂完善一下

程序代码:
<%
function setdate(str1,str2)
dim tem,tem1,tem2,tem3,tem4,tem5
if instr(str1," ")<>0 then
if str2=0 then
tem=split(str1," ") '把整个时间按空格分割,如:2008-9-4 , 8:3:2
tem1=split(tem(0),"-") '把日期分割,如:2008 , 9 , 4
tem2=split(tem(1),":") '把时间分割,如:8 , 3 , 2
if len(tem1(1))=1 then '当月长度等于1时
tem1(1)="0"&tem1(1) '在前面加0
end if
if len(tem1(2))=1 then '当日长度等于1时
tem1(2)="0"&tem1(2) '在前面加0
end if
if len(tem2(0))=1 then '当时长度等于1时
tem2(0)="0"&tem2(0) '在前面加0
end if
if len(tem2(1))=1 then '当分长度等于1时
tem2(1)="0"&tem2(1) '在前面加0
end if
if len(tem2(2))=1 then '当秒长度等于1时
tem2(2)="0"&tem2(2) '在前面加0
end if
tem3=tem1(0)&"-"&tem1(1)&"-"&tem1(2)&" "&tem2(0)&":"&tem2(1)&":"&tem2(2)
elseif str2=1 then
str1=split(str1," ")(0)
if instr(str1,"-")=0 then '判断 "-" 不存在
tem4="格式不对"
else
tem1=split(str1,"-") '把日期分割,如:2008 , 9 , 4
if len(tem1(1))=1 then '当月长度等于1时
tem1(1)="0"&tem1(1) '在前面加0
end if
if len(tem1(2))=1 then '当日长度等于1时
tem1(2)="0"&tem1(2) '在前面加0
end if
tem4=tem1(0)&"-"&tem1(1)&"-"&tem1(2)
end if
elseif str2=2 then
str1=split(str1," ")(1)
if instr(str1,":")=0 then '判断 ":" 不存在
tem5="格式不对"
else
tem2=split(str1,":") '把时间分割,如:8 , 3 , 2
if len(tem2(0))=1 then '当时长度等于1时
tem2(0)="0"&tem2(0) '在前面加0
end if
if len(tem2(1))=1 then '当分长度等于1时
tem2(1)="0"&tem2(1) '在前面加0
end if
if len(tem2(2))=1 then '当秒长度等于1时
tem2(2)="0"&tem2(2) '在前面加0
end if
tem5=tem2(0)&":"&tem2(1)&":"&tem2(2)
end if
end if
elseif str2=0 then
tem3="格式不对"
elseif str2=1 then
if instr(str1,"-")=0 then '判断 "-" 不存在
tem4="格式不对"
else
tem1=split(str1,"-") '把日期分割,如:2008 , 9 , 4
if len(tem1(1))=1 then '当月长度等于1时
tem1(1)="0"&tem1(1) '在前面加0
end if
if len(tem1(2))=1 then '当日长度等于1时
tem1(2)="0"&tem1(2) '在前面加0
end if
tem4=tem1(0)&"-"&tem1(1)&"-"&tem1(2)
end if
elseif str2=2 then
if instr(str1,":")=0 then '判断 ":" 不存在
tem5="格式不对"
else
tem2=split(str1,":") '把时间分割,如:8 , 3 , 2
if len(tem2(0))=1 then '当时长度等于1时
tem2(0)="0"&tem2(0) '在前面加0
end if
if len(tem2(1))=1 then '当分长度等于1时
tem2(1)="0"&tem2(1) '在前面加0
end if
if len(tem2(2))=1 then '当秒长度等于1时
tem2(2)="0"&tem2(2) '在前面加0
end if
tem5=tem2(0)&":"&tem2(1)&":"&tem2(2)
end if
end if
Select Case str2
Case 0 setdate=tem3
Case 1 setdate=tem4
Case 2 setdate=tem5
End Select
end function
%>
<%=setdate("2008-9-4 8:3:2",0)%> 后面的参数0为整个时间格式化<br/>
<%=setdate("2008-9-4 8:3:2",1)%> 后面的参数1为只格式化日期<br/>
<%=setdate("2008-9-4 8:3:2",2)%> 后面的参数2为只格式化时间<br/>
<%=setdate("2008-9-4",1)%> 后面的参数1为格式化日期<br/>
<%=setdate("8:3:2",2)%> 后面的参数2为格式化时间<br/>