日期:2014-02-07  浏览次数:20906 次

我 们 通 常 需 要 在 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())
%]