I have the following Arabic date in the Umm Al-Qura calendar that I want to parse into a .NET DateTime object:
الأربعاء، 17 ذو الحجة، 1436
This date is equivalent to September 30th 2015 in the Gregorian calendar.
I've been trying the following "standard" C# code to parse this date, but without success:
var cultureInfo = new CultureInfo("ar-SA");
cultureInfo.DateTimeFormat.Calendar = new UmAlQuraCalendar(); // the default one anyway
var dateFormat = "dddd، dd MMMM، yyyy"; //note the ، instead of ,
var dateString = "الأربعاء، 17 ذو الحجة، 1436";
DateTime date;
DateTime.TryParseExact(dateString, dateFormat, cultureInfo.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces, out date);
No matter what I do, the result of TryParseExact
is always false
. How do I parse this string properly in .NET?
By the way, if I start from a DateTime
object, I can create the exact date string above using ToString()
's overloads on DateTime
without problems. I just can't do it the other way around apparently.
CultureInfo.GetCultureInfoByIetfLanguageTag("ar-SA");
but it doesn't seem to fix the issue. – Levileviable