function chinadate(datetemp)
a="零一二三四五六七八九十"
b="年月日"
temp=1
for i=1 to len(datetemp)+1
if isnumeric(mid(datetemp,i,1)) then
if len(datepart("m",datetemp))=2 and i=6 then
daters=daters&mid(a,asc(mid(datetemp,i,1))-47,1)&"十"
else
if len(datepart("d",datetemp))=2 and len(datetemp)-i=1 then
daters=daters&mid(a,asc(mid(datetemp,i,1))-47,1)&"十"
else
daters=daters&mid(a,asc(mid(datetemp,i,1))-47,1)
end if
end if
else
daters=daters&mid(b,temp,1)
temp=temp+1
end if
chinadate=daters
next
end function
response.write(chinadate("2004-1-1"))
把函数名换成一个字母D比较好看,取大写DATE的意思
<SCRIPT LANGUAGE=vbs>
Function D(x)
if int(split(x,"-")(2)/10)=0 then D=D & F(split(x,"-")(2)) else _
if split(x,"-")(2) mod 10 =0 then D=D & F(int(split(x,"-")(2)/10)) & "十" else _
D=D & F(int(split(x,"-")(2)/10)) & "十" & F(split(x,"-")(2) mod 10)
D=F(split(x,"-")(0)) & "年" & MonthName(split(x,"-")(1),True) & replace(D,"一十","十") & "日"
end Function
Function F(x)
for i=1 to len(x)
if mid(x,i,1)="0" then F=F & "零" else F=F & left(MonthName(mid(x,i,1),True),1)
next
end Function
</SCRIPT>
重新粘一遍
<SCRIPT LANGUAGE=vbs>
Function EEE(x)
if int(split(x,"-")(2)/10)=0 then EEE=EEE & F(split(x,"-")(2)) else _
if split(x,"-")(2) mod 10 =0 then EEE=EEE & F(int(split(x,"-")(2)/10)) & "十" else _
EEE=EEE & F(int(split(x,"-")(2)/10)) & "十" & F(split(x,"-")(2) mod 10)
EEE=F(split(x,"-")(0)) & "年" & MonthName(split(x,"-")(1),True) & replace(EEE,"一十","十") & "日"
end Function
Function F(x)
for i=1 to len(x)
if mid(x,i,1)="0" then F=F & "零" else F=F & left(MonthName(mid(x,i,1),True),1)
next
end Function
</SCRIPT>
一共9行代码!
<SCRIPT LANGUAGE=vbs>
Function EEE(x)
if int(split(x,"-")(2)/10)=0 then EEE=EEE & F(split(x,"-")(2)) else _
if split(x,"-")(2) mod 10 =0 then EEE=EEE & F(int(split(x,"-")(2)/10)) & "十" else _
EEE=EEE & F(int(split(x,"-")(2)/10)) & "十" & F(split(x,"-")(2) mod 10)
EEE=F(split(x,"-")(0)) & "年" & MonthName(split(x,"-")(1),True) & replace(EEE,"一十","十") & "日"
end Function
Function F(x)
for i=1 to len(x)
if mid(x,i,1)="0" then F=F & "零" else F=F & left(MonthName(mid(x,i,1), True),1)
next
end Function
</SCRIPT>
Function sjcatCDate(sDate,DelimeterChar)
Dim tmpArr, dArr
If Not IsDate(sDate) Then
sjcatCDate = "非法日期"
exit function
End If
tmpArr = Split(sDate,DelimeterChar)
If not IsArray(tmpArr) Then
sjcatCDate = "非法日期"
exit function
End If
dArr = array("零","一","二","三","四","五","六","七","八","九")
For i = 0 to 9
tmpArr(0) = Replace(tmpArr(0),CStr(i),dArr(i))
Next
tmpArr(0) = tmpArr(0) & "年"
tmpArr(1) = MonthName(CInt(tmpArr(1)))
If UBound(tmpArr) = 2 Then
tmpArr(2) = CInt(tmpArr(2))
If Len(tmpArr(2)) = 2 Then
tmpArr(2) = Replace(dArr(CInt(Left(tmpArr(2),1))) & "十" & dArr(CInt(Right(tmpArr(2),1))) & "日","零","")
Else
tmpArr(2) = dArr(tmpArr(2)) & "日"
End If
End If
加上判断,并没有增加行数,祝大家新年愉快!
日期转化完美版:
<SCRIPT LANGUAGE=vbs>
Dim A,B,C,D,E
A="1002-10-31"
B=split(A,"-")(0)
C=split(A,"-")(1)
D=split(A,"-")(2)
if int(D/10)=0 then E=E & F(D) else _
if D mod 10 =0 then E=E & F(int(D/10)) & "十" else _
E=E & F(int(D/10)) & "十" & F(D mod 10)
E=F(B) & "年" & MonthName(C,True) & replace(E,"一十","十") & "日"
msgbox E
Function F(x)
for i=1 to len(x)
if mid(x,i,1)="0" then F=F & "零" else F=F & left(MonthName(mid(x,i,1), True),1)
next
end Function
</SCRIPT>
包括定义赋值显示在内14行代码搞定!(下划线分的算一行)
<SCRIPT LANGUAGE=vbs>
Dim A,B,C,D,E
A="1982-10-31"
B=split(A,"-")(0)
C=split(A,"-")(1)
D=split(A,"-")(2)
if int(D/10)=0 then E=E & F(D) else _
if D mod 10 =0 then E=E & F(int(D/10)) & "十" else _
E=E & F(int(D/10)) & "十" & F(D mod 10)
E=F(B) & "年" & MonthName(C,True) & replace(E,"一十","十") & "日"
msgbox E
Function F(x)
for i=1 to len(x)
F=F & left(MonthName(mid(x,i,1), True),1)
next
end Function
</SCRIPT>