Pregunta

I have an Asp.net application in which i have to display all dates in arabic langage . So i used this function :

 Public Function ConvertDateToArabic(ByVal _date As DateTime) As String
        Dim arabicdate As String = ""
        arabicdate += _date.Year.ToString()
        Select Case _date.Month
            Case "1"
                arabicdate += "جانفي "
                Exit Select
            Case "2"
                arabicdate += "فيفري "
                Exit Select
            Case "3"
                arabicdate += "مارس "
                Exit Select
            Case "4"
                arabicdate += "أفريل "
                Exit Select

            Case "5"
                arabicdate += "ماي "
                Exit Select
            Case "6"
                arabicdate += "جوان "
                Exit Select
            Case "7"
                arabicdate += "جويلية "
                Exit Select
            Case "8"
                arabicdate += "أوت "
                Exit Select

            Case "9"
                arabicdate += "سبتمبر "
                Exit Select
            Case "10"
                arabicdate += "أكتوبر "
                Exit Select
            Case "11"
                arabicdate += "نوفمبر "
                Exit Select
            Case "12"
                arabicdate += "ديسمبر"
                Exit Select
            Case Else
                Exit Select
        End Select
        arabicdate += "  " + _date.Day.ToString() + "  "
        Return arabicdate
    End Function

But i got wrong results for example if i put 4th 2014 i got as result 2014 فيفري 4

  1. What is the reason of this problem?
  2. How can i fix it?
¿Fue útil?

Solución

better to create a variable for the arabicMonth set within the case statement (by the way: you don't need all those Exit Select calls )

Then at the end just return String.Format("{0} {1} {2}", _date.Year, _date.Day, arabicMonth)

Also take a look here for a more elegant, culture driven way to display arabic dates

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top