我可以将日期CDate
参数转换为按字母顺序排列的日期
例如:将'08.12.1994'
转换为'Eighth December : Nineteen Hundred Ninety-Four'
答案 0 :(得分: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