私は日付の変換に取り組んHijri
でいます。Gregorian
ただし、次のNullReferenceException
エラー メッセージが表示されます。
オブジェクト参照がオブジェクト インスタンスに設定されていません。
pprivate HttpContext cur;
private const int startGreg=1900;
private const int endGreg=2100;
private 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"};
private CultureInfo arCul;
private CultureInfo enCul;
private HijriCalendar h;
private GregorianCalendar g;
public void Dates()
{
cur = HttpContext.Current;
arCul=new CultureInfo("ar-SA");
enCul=new CultureInfo("en-US");
h=new HijriCalendar();
g=new GregorianCalendar(GregorianCalendarTypes.USEnglish);
arCul.DateTimeFormat.Calendar=h;
}
public string HijriToGreg(string hijri)
{
if (hijri.Length<=0)
{
cur.Trace.Warn("HijriToGreg :Date String is Empty");
return "";
}
try
{
DateTime tempDate=DateTime.ParseExact(hijri,allFormats,
arCul.DateTimeFormat,DateTimeStyles.AllowWhiteSpaces);
return tempDate.ToString("yyyy/MM/dd",enCul.DateTimeFormat);
}
catch (Exception ex)
{
cur.Trace.Warn("HijriToGreg :"+"\n"+ex.ToString());
return "";
}
}