tags:

views:

393

answers:

4

Hi i have this C# code for example

DateTime.Now.ToString("MMMM dd, yyyy");

Now the current thread is loading the arabic culture. So the result is like this

???? 19, 2010

But i don't want the '2010' and the '19' to be in english. I tried

DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.GetCultureInfo("ar-lb"));

gave the same result. So any idea?

+2  A: 

We use Arabic numerals in English. As such, what you're seeing is the correct - and only possible - behaviour.

ceejayoz
+5  A: 

As a quick test, I wrote this to list all the cutures which don't have "2010" in the year:

        foreach (var ci in 
            from c in CultureInfo.GetCultures(CultureTypes.AllCultures)
            where !c.IsNeutralCulture
            let date = DateTime.Now.ToString("MMMM dd, yyyy", c)
            where !date.Contains("2010")
            orderby c.Name
            select new {c.Name, date})
        {
            Console.WriteLine("{0} : {1}", ci.Name, ci.date);
        }

the results are:

ar-SA : ربيع الأول 05, 1431
dv-MV : ربيع الأول 06, 1431
prs-AF : ربيع الأول 06, 1431
ps-AF : ربيع الأول 06, 1431
th-TH : กุมภาพันธ์ 19, 2553

To convert the numbers to Arabic text, it looks like this "NumToArabicString" project will do it. It doesn't look like there's anything built into the .net framework though.

James Kolpack
A: 

Thy this WorkAround(just list all cultres you want to use this numerals in the string array):

private static class ArabicNumeralHelper
{
    public static string ConvertNumerals(this string input)
    {
        if (new string[] { "ar-lb", "ar-SA" }.Contains(Thread.CurrentThread.CurrentCulture.Name))
        {
            return input.Replace('0', '\u06f0')
                    .Replace('1', '\u06f1')
                    .Replace('2', '\u06f2')
                    .Replace('3', '\u06f3')
                    .Replace('4', '\u06f4')
                    .Replace('5', '\u06f5')
                    .Replace('6', '\u06f6')
                    .Replace('7', '\u06f7')
                    .Replace('8', '\u06f8')
                    .Replace('9', '\u06f9');
        }
        else return input;
    }
}

Then use the method, for all of your strings you want to have 'central arabic numerals' in, like this:

DateTime.Now.ToString().ConvertNumerals();

I hope this helps.

Marcel Benthin
The Wikipedia article you link to says that the standard Arabic numerals are used in the Arab world and that the Eastern Arabic numerals you refer to are only used in a few specific nations.
ceejayoz
A: 

I'm also facing this issue. I searched everywhere and seems the only solution is to manually convert the digits. You could use the CurrentCulture.NumberFormat.NativeDigits array instead of explicitly providing the Unicode characters to get the proper Arabic-Indic digits but as far as builtin support by culture-aware classes such as DateTime it seems unimplemented or something. I wish I'd saw an official confirmation, though, from someone working on these.