I need to convert strings to DateTime objects that are in non-English languages. I've seen many examples of converting DateTime to strings in other languages, but not the other way around.
This doesn't seem to 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);
Additionally, I need to handle strings that are in other calendars. This is what I tried and it doesn't seem to work either.
CultureInfo provider = new CultureInfo("ar-AE"); // Arabic - United Arab Emirates
provider.DateTimeFormat.Calendar = new System.Globalization.HijriCalendar();
// Wednesday, March 16, 2011, 11 Rabi second in 1432
string sample = " ?11 ???? ???? 1432 ";
DateTime result;
DateTime expected = new DateTime(2011, 3, 16); // ?
bool b;
b = DateTime.TryParse(sample, provider, DateTimeStyles.None, out result);
Assert.IsTrue(b);
Assert.AreEqual(expected, result);
What am I missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…