Cómo convertir Fecha gregoriana a Fecha persa?


Quiero convertir una fecha gregoriana personalizada a una fecha persa en C#. Por ejemplo, tengo una cadena con este contenido:

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

Ahora quiero tener:

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

O

String PersianDate = 1392/08/02

Gracias

Author: Ali Seyedi, 2015-06-06

6 answers

Utilice el 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)));
 42
Author: Alioza,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-13 06:31:47

Puedes usar PersianDateTime:

PM> Install-Package PersianDateTime

La Referencia: PersianDateTime

Puede usar string.Split() si necesita personalización.

 4
Author: Elnaz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-02 10:23:17

En Windows 10, usando framework 4+:

Console.WriteLine(Convert.ToDateTime("1392/08/02",new CultureInfo("fa-IR")));

O

Console.WriteLine(DateTime.Parse("1392/08/02", new CultureInfo("fa-IR")));
 1
Author: Amir,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-02 11:35:49

Sumando otras respuestas, puedes obtener la primera usando PersianDateTime :

var gregorianDate = "Thursday, October 24, 2013";
var date = DateTime.Parse(gregorianDate);
var persianDate = new PersianDateTime(date);
var result = persianDate.ToString("dddd d MMMM yyyy");
 1
Author: Ali Seyedi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-27 21:00:55
    DateTime date = new DateTime(2013, 10, 24);
    var calendar = new PersianCalendar();
    var persianDate = new DateTime(calendar.GetYear(date), calendar.GetMonth(date), calendar.GetDayOfMonth(date));
    var result = persianDate.ToString("yyyy MMM ddd", CultureInfo.GetCultureInfo("fa-Ir"));
 0
Author: Oleg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-06 14:11:48

Sugiero usar MD.PersianDateTime, puedes usarlo tan fácil como DateTime:

var persianDateTimeNow = PersianDateTime.Now;
persianDateTimeNow.EnglishNumber = true;
Console.WriteLine(persianDateTimeNow.ToString());

Https://github.com/Mds92/MD.PersianDateTime

 0
Author: Mohammad Dayyan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-03 12:19:15