VB中将日期转换为大写

jumay 2007-12-03 08:16:20
VB中如何将日期转换为大写,例如:2007-12-04转换后为贰零零柒年拾贰月肆日,请问VB代码怎样写
...全文
139 2 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
  • 打赏
  • 举报
回复
发帖
VB基础类

7635

社区成员

VB 基础类
社区管理员
  • VB基础类社区
加入社区
帖子事件
创建了帖子
2007-12-03 08:16
社区公告
暂无公告