VB编写一个将日期值转换为中文字符串格式的函数并调用

2024-12-04 16:19:24
推荐回答(3个)
回答1:

Public Function CCDate$(ByVal MyDate As Date)
y = CStr(Year(MyDate)): m = Month(MyDate): d = Day(MyDate)
For i = 1 To 4
CCDate = CCDate & Mid("Ο一二三四五六七八九", Val(Mid(y, i, 1)) + 1, 1)
Next
CCDate = CCDate & "年"
CCDate = CCDate & Trim(Mid("一 二 三 四 五 六 七 八 九 十 十一十二", m * 2 - 1, 2)) & "月"
CCDate = CCDate & Trim(Mid(" 十二十三十", (d \ 10) * 2 + 1, 2)) & Trim(Mid(" 一二三四五六七八九", (d Mod 10) + 1, 1)) & "日"
End Function
'请注意 字符串中 看不到的空格 别少了

回答2:

Private Function CCDate$(d As Date)
CCDate = fun(Year(d)) & "年" & fun(Month(d)) & "月" & fun(Day(d)) & "日"
CCDate = Replace(CCDate, "〇日", "十日")
End Function

Private Function fun$(n As Integer)
For i = 1 To Len(CStr(n))
fun = fun + Choose(Val(Mid(CStr(n), i, 1)) + 1, "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九")
Next
End Function

回答3:

Public Function CCDate$(ByVal MyDate As Date)
y = CStr(Year(MyDate)): m = Month(MyDate): d = Day(MyDate)
For i = 1 To 4
CCDate = CCDate & Mid("Ο一二三四五六七八九", Val(Mid(y, i, 1)) + 1, 1)
Next
CCDate = CCDate & "年"
CCDate = CCDate & Trim(Mid("一 二 三 四 五 六 七 八 九 十 十一十二", m * 2 - 1, 2)) & "月"
CCDate = CCDate & Trim(Mid(" 十二十三十", (d \ 10) * 2 + 1, 2)) & Trim(Mid(" 一二三四五六七八九", (d Mod 10) + 1, 1)) & "日"
End Function