Search code examples
c#dategregorian-calendardate-conversionpersian

How convert Gregorian date to Persian date?


I want to convert a custom Gregorian date to Persian date in C#. For example, i have a string with this contents:

string GregorianDate = "Thursday, October 24, 2013";

Now i want to have:

string PersianDate = پنج‌شنبه 2 آبان 1392 ;

or

string PersianDate = 1392/08/02

Thanks


Solution

  • Use the PersianCalendar:

    string GregorianDate = "Thursday, October 24, 2013";
    DateTime d = DateTime.Parse(GregorianDate);
    PersianCalendar pc = new PersianCalendar();
    Console.WriteLine(string.Format("{0}/{1}/{2}", pc.GetYear(d), pc.GetMonth(d), pc.GetDayOfMonth(d)));