VBS 短暂的美,两个函数,整齐的代码,简单的思路,拯救年轻的大兵
<script language=vbs>
dim x,a,b,c,d,e
x="03-9-2 12:45"
a=split(split(x)(0),"-")(0)
b=split(split(x)(0),"-")(1)
c=split(split(x)(0),"-")(2)
d=split(split(x)(1),":")(0)
e=split(split(x)(1),":")(1)
if len(a)=1 then a ="0" & a
if len(b)=1 then b ="0" & b
if len(c)=1 then c ="0" & c
if len(d)=1 then d ="0" & d
if len(e)=1 then e ="0" & e
x=a & "-" & b &"-"& c & " " & d & ":"& e
msgbox x
</script >
<%
Dim DateStrTest
DateStrTest="2003-10-3 9:42"
response.write FormatDate(DateStrTest)
Function FormatDate(DateStr)
Dim YearStr
Dim MonthStr
Dim DayStr
Dim HourStr
Dim MinuteStr
DateStr=FormatDateTime(DateStr)
YearStr=Year(DateStr)
MonthStr=Month(DateStr)
DayStr=Day(DateStr)
HourStr=Hour(DateStr)
MinuteStr=Minute(DateStr)
If Len(MonthStr)=1 Then MonthStr="0"&MonthStr
If Len(DayStr)=1 Then DayStr="0"&DayStr
If Len(HourStr)=1 Then HourStr="0"&HourStr
FormatDate=YearStr&"-"&MonthStr&"-"&DayStr&" "&HourStr&":"&MinuteStr
End Function
%>
下面这段代码是最好的:
<%
dim YTime,MTime,DTime,HTime,MiTime
YTime=year(now())
MTime=Month(now())
DTime=Day(now())
HTime=Hour(now())
MiTime=Minute(now())
if len(YTime)=1 then
Ytime="0"&YTime
end if
if len(MTime)=1 then
Mtime="0"&MTime
end if
if len(DTime)=1 then
Dtime="0"&DTime
end if
if len(HTime)=1 then
Htime="0"&HTime
end if
if len(MiTime)=1 then
Mitime="0"&MiTime
end if
Response.Write "格式化的日期时间: "&Ytime&"-"&Mtime&"-"&Dtime&"
<%
dim YTime,MTime,DTime,HTime,MiTime
YTime=year(now())
MTime=Month(now())
DTime=Day(now())
HTime=Hour(now())
MiTime=Minute(now())
if len(YTime))=1 then
Ytime="0"&YTime
end if
if len(MTime))=1 then
Mtime="0"&MTime
end if
if len(DTime))=1 then
Dtime="0"&DTime
end if
if len(HTime))=1 then
Htime="0"&HTime
end if
if len(MiTime))=1 then
Mitime="0"&MiTime
end if
Respons.Write "格式化的日期时间: "&Ytime&"-"&Mtime&"-"&Dtime&" "&Htime&":"&Mitime
%>