獲得ASP的中文日期文字

來源:互聯網
上載者:User
中文|字串|字串 我 們 通 常 需 要 在 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())
%]



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.