现在我正在使用回历日期并尝试使用以下代码将它们转换为公历日期:
string HijriDate;
string[] allFormats ={"yyyy/MM/dd","yyyy/M/d",
"dd/MM/yyyy","d/M/yyyy",
"dd/M/yyyy","d/MM/yyyy","yyyy-MM-dd",
"yyyy-M-d","dd-MM-yyyy","d-M-yyyy",
"dd-M-yyyy","d-MM-yyyy","yyyy MM dd",
"yyyy M d","dd MM yyyy","d M yyyy",
"dd M yyyy","d MM yyyy","MM/dd/yyyy"};
CultureInfo enCul = new CultureInfo("en-US");
CultureInfo arCul = new CultureInfo("ar-SA");
arCul.DateTimeFormat.Calendar = new System.Globalization.HijriCalendar();
DateTime tempDate = DateTime.ParseExact(HijriDate, allFormats, arCul.DateTimeFormat, DateTimeStyles.AllowWhiteSpaces);
return tempDate.ToString("MM/dd/yyyy");
此代码适用于所有日期,除了每月第 30 天的日期,如下所示:
30/10/1433
,30/12/1432
或30/05/1433
等等,所以如何处理该日期并将其转换为对应的公历