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 (also known as Latin or West Arabic digits) - I want East Arabic numbers like "٢".
I tried
DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.GetCultureInfo("ar-lb"));
gave the same result. So any idea?
You can use the Windows.Globalization.NumberFormatting.NumeralSystemTranslator class to translate between the Latin and any of the supported numeral systems. To translate to Arabic, set the
NumeralSystem
property to"Arab"
, then you can call theTranslateNumerals
method.Alternatively you can just use Windows.Globalization.DateTimeFormatting.DateTimeFormatter class directly.
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 support any other languages in addition to the Arabic-Indic digits, but as far as builtin support by culture-aware classes such asDateTime
it seems unimplemented or something.As a quick test, I wrote this to list all the cutures which don't have "2010" in the year:
the results are:
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.
Try this:
We use Arabic numerals in English. As such, what you're seeing is the correct - and only possible - behaviour.
Thy this workaround (just list all cultures you want to use this numerals in the string array):
Then use the method, for all of your
strings
you want to have 'central Arabic numerals' in, like this: