• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

获得ASP的中文日期字符串

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 15次 | 进入软件测试论坛讨论

领测软件测试网 我 们 通 常 需 要 在 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())
%]

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网