If you know the exact format, you can force it using TryParseExact :
b = DateTime.TryParseExact(sample, "dddd d MMMM yyyy", provider, DateTimeStyles.None, out result);
However, in your case this does not work. To find the problem, try making the return path:
Console.WriteLine(expected.ToString("dddd d MMMM yyyy", provider));
And the result: "الأربعاء 16 مارس 2011", which (you can probably read which is better than me) differs from your input in one character: .NET uses (and expects) hamza, your input does not have it. If we modify the input in this way, everything will work:
CultureInfo provider = new CultureInfo("ar-AE"); // Arabic - United Arab Emirates string sample = "الأربعاء 16 مارس 2011"; // Arabic date in Gregorian calendar DateTime result; DateTime expected = new DateTime(2011, 3, 16); // the expected date bool b; b = DateTime.TryParse(sample, provider, DateTimeStyles.None, out result); Assert.IsTrue(b); Assert.AreEqual(expected, result);
Mormegil
source share