I am trying to convert a specific Persian date to Gregorian with no success. I have tried below code but I get compiler error saying:
DateTime does not contain a constructor that takes 4 arguments.
using System.Globalization;
DateTime dt = new DateTime(year, month, day, new PersianCalendar());
I have also tried below way but I get the same Persian date (obj in below code) that I have passed into ConvertToGregorian
function and not the Gregorian date:
public static DateTime ConvertToGregorian(this DateTime obj)
{
GregorianCalendar gregorian = new GregorianCalendar();
int y = gregorian.GetYear(obj);
int m = gregorian.GetMonth(obj);
int d = gregorian.GetDayOfMonth(obj);
DateTime gregorianDate = new DateTime(y, m, d);
var result = gregorianDate.ToString(CultureInfo.InvariantCulture);
DateTime dt = Convert.ToDateTime(result);
return dt;
}
Please note that my CultureInfo.InvariantCulture
is English US.