【问题标题】:Rdlc convert date to alphabet numberRdlc 将日期转换为字母数字
【发布时间】:2017-05-25 09:50:49
【问题描述】:

我可以将日期CDate 参数转换为字母日期

例如:将'08.12.1994' 转换为'Eighth December : Nineteen Hundred Ninety-Four'

【问题讨论】:

  • 不,我认为你不能轻易做到。你宁愿在你的代码中转换它并传递已经转换的参数。
  • @Pikoh 那么,有没有 c# 的内置方法可以将 int 转换为字母?
  • 我不知道什么是内置的。你可以试试Humanizer

标签: c# vb.net reporting rdlc


【解决方案1】:

如果你保证日期是 DD.MM.YYYY 格式,这个 VB 代码可能就是你想要的。

Function ConvertDate(ByVal date As String) As String
    Dim textDate As String = ""
    Dim nDay As Integer = CInt(date.Split(".")(0))
    Dim nMonth As Integer = CInt(date.Split(".")(1))
    Dim nYear As Integer = CInt(date.Split(".")(2))
    Dim hundreds As Integer = 0
    Dim notHundreds As Integer = 0

    //Convert day to text.
    Select Case (nDay)
        Case 1
            textDate += "First"
        //Fill in cases 2-30
        Case 31
            textDate += "Thirty-First"
    End Select

    //Add your separator.
    textDate += " "

    //Convert the month to text.   
    Select Case (nMonth)
        Case 1
            textDate += "January"
        //Finn in cases 2-11
        Case 12
            textDate += "December"
    End Select

    //Add your separator.
    textDate += " : "

    //Split the year.
    hundreds = nYear / 100
    notHundreds = nYear - 100 * hundreds

    //Add the hundreds part of the date if there is one.
    If hundreds <> 0 Then
        textDate += NumberUnder100ToText(hundreds)
        textDate += "Hundred "
    End If

    //Add the not hundreds part if there is one.
    If notHundreds <> 0 Then
        textDate += NumberUnder100ToText(notHundreds)
    End If

    //Remove extra trailing space if present.
    textDate = textDate.Trim()

    Return textDate
End Function

Function NumberUnder100ToText(ByVal number As Integer) As String
    Dim text As String = ""

    If number < 20 Then
        //Covers 1 to 19
        Select Case (number)
            Case 0 //Do nothing
                text = ""
            Case 1
                text = "One"
            //Cases 2-18
            Case 19
                text = "Nineteen"
        End Select
    Else
        //Add the 10s place
        Select Case (number / 10)
            Case 2
                text = "Twenty"
            //Cases 3-8
            Case 9
                text = "Ninety"
        End Select

        //Add the 1s place
        If (number Mod 10 <> 0) Then
            text += "-"
            text += NumberUnder100ToText(number Mod 10)
        End If
    End If

    Return text
End Function

【讨论】:

    猜你喜欢
    • 2018-09-30
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 2013-04-15
    相关资源
    最近更新 更多