VB中将日期转换为大写

jumay 2007-12-03 08:16:20
VB中如何将日期转换为大写,例如:2007-12-04转换后为贰零零柒年拾贰月肆日,请问VB代码怎样写
...全文
171 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzyong00 2007-12-03
  • 打赏
  • 举报
回复
随手写的,不知有没有错
zzyong00 2007-12-03
  • 打赏
  • 举报
回复
Option Explicit

Private Sub Form_Load()
Dim col As New Collection
col.Add "零", "0"
col.Add "壹", "1"
col.Add "贰", "2"
col.Add "叁", "3"
col.Add "肆", "4"
col.Add "伍", "5"
col.Add "陆", "6"
col.Add "柒", "7"
col.Add "捌", "8"
col.Add "玖", "9"
col.Add "拾", "10"
Dim d As Date
d = "2007-010-0031"
'If Not IsDate(d) Then
' MsgBox "日期错误", vbCritical
' Exit Sub
'End If
Dim arr() As String, result As String
arr = Split(CStr(d), "-")
Dim i As Integer
For i = 1 To Len(arr(0))
result = result & col.Item(Mid(arr(0), i, 1))
Next i
result = result & "年"
'Debug.Print result
If Val(arr(1)) > 10 Then
result = result & "拾" & col.Item(Right(arr(1), 1)) & "月"
Else
result = result & col.Item(arr(1)) & "月"
End If
'Debug.Print result
If Val(arr(2)) > 19 Then
result = result & col.Item(Left(arr(2), 1)) & "拾" & col.Item(Right(arr(2), 1)) & "日"
ElseIf Val(arr(2)) > 10 Then
result = result & "拾" & col.Item(Right(arr(2), 1)) & "日"
Else
result = result & col.Item(arr(2)) & "日"
End If
Debug.Print result
End Sub

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧