none
How to convert the month name in english text in datetime to arabic text using C#? RRS feed

  • Question

  • I have a date which is displayed on 12 July 2013. I am using the format "dd MMMM yyyy". I want to display the month text i.e. July in Arabic text. Is there anyway? 

    Am getting يوليه as result instead يوليو, My client, saying the month of July is “يوليو” in Arabic, while on the website it is showing as “يوليه”. Which is wrong,
    can anyone help me on this? 

    Please find the code below.


    CultureInfo uiCulture1 = CultureInfo.CurrentUICulture; //'ar-AE' DateTime dDateTime2 = DateTime.Parse(dt.ToString(), uiCulture1, System.Globalization.DateTimeStyles.AssumeLocal); lblDate.Value = dt.ToString("dd MMMM yyyy");

    Am getting correct value in the local machine when am hosting the application to remote server am getting the wrong result. 

    Thursday, October 12, 2017 8:41 AM

All replies

  • I'm guessing the difference is the regional settings on the different machines.

    Are you sure the CurrentUICulture is actually the same on both machines? (I'm not familiar with Arabic so is it possible there are several variants?).

    You could test this by creating the culture directly with:

    CultureInfo uiCulture1 = new CultureInfo("ar-AE");

    You could also pass the culture to the 'ToString()' method when parsing to text (it should be picking up the current culture anyway, but if that is different on the different machines as suggested above it could explain the different results). e.g.

    lblDate.Value = dt.ToString("dd MMMM yyyy", uiCulture1);

    Thursday, October 12, 2017 9:04 AM
  • I'm guessing the difference is the regional settings on the different machines.

    Are you sure the CurrentUICulture is actually the same on both machines? (I'm not familiar with Arabic so is it possible there are several variants?).

    You could test this by creating the culture directly with:

    CultureInfo uiCulture1 = new CultureInfo("ar-AE");

    You could also pass the culture to the 'ToString()' method when parsing to text (it should be picking up the current culture anyway, but if that is different on the different machines as suggested above it could explain the different results). e.g.

    lblDate.Value = dt.ToString("dd MMMM yyyy", uiCulture1);

    I have tried all the possibility,

    dt.ToString("d MMMM yyyy", System.Globalization.CultureInfo.GetCultureInfo("ar-AE"));

    i tired to get month only from the date 

     string arabicMonth = new CultureInfo("ar-AE").DateTimeFormat.GetMonthName(dt.Month);

    All input giving proper output while am working in local machine but when i put the code files to remote server the result is wrong. 

    Is it this issue cause by machine settings, my local machine is Windows 7 and the server is Windows 10

    Thursday, October 12, 2017 12:22 PM
  • Hello Reshmy Sandeep,

    Have you tested to force your current thread to use ar-AE culture? 

    Like this code:

       DateTime dt = DateTime.Now;
       Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-AE");
       textBox1.Text = dt.ToString("dd MMMM yyyy");

    Then what's the result?

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 13, 2017 8:14 AM
    Moderator