将阿拉伯数字日期转换为中文数字日期格式(ASP)

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 sfchina 的 blog

刚才看到一个兄弟提的问题,做完了才发现已经结贴,郁闷呀~~
只是看到这个东西还算有用,所以贴出来自赏呵呵
思路:
一开始想到用select,用for循环将每位阿拉伯数字转换成对应的中文,然后想到其实可以用数组,这样子比较少些代码,毕竟0~9,可以对应起来,可是~问题出现了,对于10~31,要变成“贰拾壹” 这样格式,呵呵~加一个判断,嗯~11可不能转换成“壹拾壹”,在加判断
呵呵~基本好了,还需要判断是不是数字呢,ok!这下子应该是可以over了!
<%
t=now()
function datetostr(t)
 dim stryear,strmonth,strday,strresult
 stryear = year(t)
 strmonth = month(t)
 strday = day(t)
 datetostr = casei(stryear) & "年" & casei(strmonth) & "月" & casei(strday) & "日"
end function
function casei(i)
 dim arrnum,arrcnnum
 if(isnumeric(i))then
  arrnum = split(i)
  arrcnnum=split("零,壹,贰,叁,肆,伍,陆,柒,捌,玖",",")
  if( i<10 or i>31)then
   for it=1 to len(i)
   strresult = strresult & arrcnnum(cint(mid(i,it,1)))
   next
  elseif(i > 9 and i < 12)then
  strresult = "拾" & arrcnnum(cint(mid(i,2,1)))
  else
  strresult = arrcnnum(cint(mid(i,1,1))) & "拾" & arrcnnum(cint(mid(i,2,1)))
  end if
 end if
 casei = strresult
end function
response.write(datetostr(t))
%>

本文关键:将阿拉伯数字日期转换为中文数字日期格式(ASP)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top