First of all, Am C# starter, so if there is edit for the code, I posted please go ahead and optimize it.
By reading and trying the code, ( BTW very old posts here and there!)
And after referring to
عرض الوقت والتاريخين الهجري والميلادي في برنامجك سي شارب
I beginning to read the problem more clearly,
Case 1
When i used below line i got 1441 محرم 24
DateTime.Now.ToString("yyyy MMMM dd", new System.Globalization.CultureInfo("ar-SA"))
Now keep an eye on MMMM and ar-SA specifically to show the month called محرم.
Problems here is you get 1441 in English!
So
Case 2
To take this line one step further i used the convert to Arabic numbers method...
This code shall change any digit to arabic/hindi charset...
public static string ConvertToEasternArabicNumerals(string input)
{
System.Text.UTF8Encoding utf8Encoder = new UTF8Encoding();
System.Text.Decoder utf8Decoder = utf8Encoder.GetDecoder();
System.Text.StringBuilder convertedChars = new System.Text.StringBuilder();
char[] convertedChar = new char[1];
byte[] bytes = new byte[] { 217, 160 };
char[] inputCharArray = input.ToCharArray();
foreach (char c in inputCharArray)
{
if (char.IsDigit(c))
{
bytes[1] = Convert.ToByte(160 + char.GetNumericValue(c));
utf8Decoder.GetChars(bytes, 0, 2, convertedChar, 0);
convertedChars.Append(convertedChar[0]);
}
else
{
convertedChars.Append(c);
}
}
return convertedChars.ToString();
}
Code combined:
DateHelper.ConvertToEasternArabicNumerals(DateTime.Now.ToString("yyyy MMMM dd", new System.Globalization.CultureInfo("ar-SA")));