設(shè)為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

返回列表 發(fā)新帖
查看: 1947|回復(fù): 4
打印 上一主題 下一主題

[模塊/函數(shù)] 實(shí)現(xiàn)日期大寫顯示

[復(fù)制鏈接]

點(diǎn)擊這里給我發(fā)消息

跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2002-10-4 09:00:00 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
引貼
實(shí)現(xiàn)日期大寫顯示,顯示效果 : 二〇〇二年十月四日
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
可自己改改適合自己的需要
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱
2#
發(fā)表于 2002-10-4 19:51:00 | 只看該作者
呵呵,站長真仔細(xì)呀,把判斷十以上的月份處理都寫上了。可有的時(shí)間,人家不須要您搞的這樣復(fù)雜呀。
http://ctxi.cn/bbs/dispbbs.asp?boardID=2&RootID=14523&ID=14523
我作的同你的相比怎樣?

[此貼子已經(jīng)被HG于2002-10-4 11:51:19編輯過]

3#
發(fā)表于 2002-10-6 07:29:00 | 只看該作者
數(shù)字轉(zhuǎn)為大寫我用過,日期直接選定顯示中文格式不就行了嗎?
各位是想練練招吧?程序?qū)懙氖遣诲e(cuò),千萬別誤導(dǎo)人家喔。
4#
發(fā)表于 2002-10-7 07:22:00 | 只看該作者
對不起,我說錯(cuò)了,這樣的轉(zhuǎn)換有些地方還是會(huì)用到,雖然我沒用過。
HG的例子改成這樣好像短一些,還有更短的嗎?:
Public Function AAA(number As Variant) As String
Select Case number
      Case 0: AAA = "○"
      Case 1: AAA = "一"
      Case 2: AAA = "二"
      Case 3: AAA = "三"
      Case 4: AAA = "四"
      Case 5: AAA = "五"
      Case 6: AAA = "六"
      Case 7: AAA = "七"
      Case 8: AAA = "八"
      Case 9: AAA = "九"
      Case 10: AAA = "十"
      Case 20: AAA = "二十"
      Case 30: AAA = "三十"
      Case 11 To 31: AAA = AAA(Int(number / 10)) & "十" & AAA(number Mod 10)
   End Select
End Function

Public Function BBB(ChnDate As Variant) As String
    BBB = AAA(Mid(Year(ChnDate), 1, 1)) & AAA(Mid(Year(ChnDate), 2, 1))
    BBB = BBB & AAA(Mid(Year(ChnDate), 3, 1)) & AAA(Mid(Year(ChnDate), 4, 1)) & "年"
    BBB = BBB & AAA(Month(ChnDate)) & "月" & AAA(Day(ChnDate)) & "日"
End Function

運(yùn)行結(jié)果:
Print BBB(Now())
二○○二年十月六日
Print BBB("1982-5-3")
一九八二年五月三日
5#
發(fā)表于 2002-10-7 16:40:00 | 只看該作者
Type my_case_date
      my_case_year  As String
      my_case_month As String
      my_case_daily As String
End Type

Public Function number_case_hz(my_str_num As String) As String
If IsNull(my_str_num) Then
   MsgBox "錯(cuò)誤:不可轉(zhuǎn)入空值", vbOKOnly, "err_info"
Else
   Select Case my_str_num
          Case "0": number_case_hz = "零"
          Case "1": number_case_hz = "壹"
          Case "2": number_case_hz = "貳"
          Case "3": number_case_hz = "毿"
          Case "4": number_case_hz = "肆"
          Case "5": number_case_hz = "伍"
          Case "6": number_case_hz = "陸"
          Case "7": number_case_hz = "柒"
          Case "8": number_case_hz = "捌"
          Case "9": number_case_hz = "玖"
   End Select
End If
End Function
Public Function my_case_date(my_date As Date, my_info_hz As Boolean) As my_case_date

If IsNull(my_date) Or IsNull(my_info_hz) Then
  MsgBox "錯(cuò)誤:不可轉(zhuǎn)入空值", vbOKOnly, "err_info"
  Exit Function
End If

Dim str_case_date As String
Dim my_date_year As String
Dim my_date_month As String
Dim my_date_daily As String
Dim my_len As Integer

With my_case_date
.my_case_year = ""
.my_case_month = ""
.my_case_daily = ""
End With

str_case_date = CStr(Format(my_date, "yyyy/mm/dd"))
my_date_year = Left(str_case_date, 4)
my_date_month = Mid(str_case_date, 6, 2)
my_date_daily = Right(str_case_date, 2)

If my_info_hz = fasle Then
  With my_case_date
     .my_case_year = my_date_year
     .my_case_month = my_date_month
     .my_case_daily = my_date_daily
  End With
Else
my_len = 1
While my_len <= 4
  With my_case_date
       .my_case_year = .my_case_year + number_case_hz(Mid(my_date_year, my_len, 1))
  End With
  my_len = my_len + 1
Wend

my_len = 1
If CInt(my_date_month) < 10 Then
  While my_len <= 2
     my_case_date.my_case_month = my_case_date.my_case_month + number_case_hz(Mid(my_date_month, my_len, 1))
     my_len = my_len + 1
  Wend
Else
  If CInt(my_date_month) = 10 Then
     my_case_date.my_case_month = "壹拾"
  Else
    If CInt(my_date_month) = 11 Then
        my_case_date.my_case_month = "壹拾壹"
     Else
       If CInt(my_date_month) = 12 Then
         my_case_date.my_case_month = "壹拾貳"
        End If
    End If
  End If
End If

my_len = 1
If CInt(my_date_daily) < 10 Then
   While my_len <= 2
      my_case_date.my_case_daily = my_case_date.my_case_daily + number_case_hz(Mid(my_date_daily, my_len, 1))
      my_len = my_len + 1
   Wend
Else
  If CInt(my_date_daily) = 10 Then
     my_case_date.my_case_daily = "壹拾"
    Else
      If (CInt(my_date_daily) < 20 And CInt(my_date_daily) > 10) Or (CInt(my_date_daily) < 30 And CInt(my_date_daily) > 20) Then
         my_case_date.my_case_daily = number_case_hz(Left(my_date_daily, 1)) + "拾" + number_case_hz(Right(my_date_daily, 1))
        Else
          If CInt(my_date_daily) = 20 Then
             my_case_date.my_case_daily = "貳拾"
            Else
              If CInt(my_date_daily) = 30 Then
                my_case_date.my_case_daily = "毿拾"
                Else
                  If CInt(my_date_daily) = 31 Then
                    my_case_date.my_case_daily = "毿拾壹"
                   End If
              End If
            End If
        End If
    End If
End If
End If
End Fu
這是最終效果,專門為支票的格式處理過的,而不是一般的通用日期,大寫轉(zhuǎn)換,現(xiàn)在可以加一個(gè)參數(shù),來實(shí)現(xiàn)分段輸出數(shù)字和漢字格式。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2024-10-23 10:20 , Processed in 0.135405 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表