中文|字串|字串 我 們 通 常 需 要 在 WEB 頁 面 上 寫 上 當 前 的 日 期 , 可 能 使 用 客 戶 端 script , 或 者 使 用 ASP 。 使 用 ASP 的 一 個 特 點 是 , 它 產 生 的 效 果 看 起 來 是 靜 態 的 頁 面 ,但 實 際 上 它 是 動 態 生 成 的 。 如 果 你 希 望 用ASP 顯 示 一個 中 文 的 日 期 , 則 需 要 轉 化 一 下 。 下 面 是 用 來 轉 化 的 函 數 及 其 調 用 實 例 。
[[ 函數實現 ]]
[%
'======================================================
' 函數 Date2Chinese
' 功能:獲得中文日期的字串(如一九九八年五月十二日)
' 參數: iDate 要轉化的日期
' 返回: 中文日期的字串
'======================================================
Function Date2Chinese(iDate)
Dim num(10)
Dim iYear
Dim iMonth
Dim iDay
num(0) = "〇"
num(1) = "一"
num(2) = "二"
num(3) = "三"
num(4) = "四"
num(5) = "五"
num(6) = "六"
num(7) = "七"
num(8) = "八"
num(9) = "九"
iYear = Year(iDate)
iMonth = Month(iDate)
iDay = Day(iDate)
Date2Chinese = num(iYear \ 1000) + _
num((iYear \ 100) Mod 10) + num((iYear _
\ 10) Mod 10) + num(iYear Mod _
10) + "年"
If iMonth ]= 10 Then
If iMonth = 10 Then
Date2Chinese = Date2Chinese + _
"十" + "月"
Else
Date2Chinese = Date2Chinese + _
"十" + num(iMonth Mod 10) + "月"
End If
Else
Date2Chinese = Date2Chinese + _
num(iMonth Mod 10) + "月"
End If
If iDay ]= 10 Then
If iDay = 10 Then
Date2Chinese = Date2Chinese + _
"十" + "日"
ElseIf iDay = 20 Or iDay = 30 Then
Date2Chinese = Date2Chinese + _
num(iDay \ 10) + "十" + "日"
ElseIf iDay ] 20 Then
Date2Chinese = Date2Chinese + _
num(iDay \ 10) + "十" + _
num(iDay Mod 10) + "日"
Else
Date2Chinese = Date2Chinese + _
"十" + num(iDay Mod 10) + "日"
End If
Else
Date2Chinese = Date2Chinese + _
num(iDay Mod 10) + "日"
End If
End Function
%]
[[ 調 用 舉 例 ]]
[%
response.write date2Chinese(date())
%]