如何将公历日期转换为波斯日期?我正在尝试将自定义公历日期转换为C#中的波斯日期。例如,我有一个包含以下内容的字符串:stringGregorianDate="Thursday,October24,2013";现在我想要:或stringPersianDate=1392/08/02感谢使用PersianCalendar:stringGregorianDate="2013年10月24日星期四";日期时间d=DateTime.Parse(GregorianDate);PersianCalendarpc=newPersianCalendar();Console.WriteLine(string.Format("{0}/{1}/{2}",pc.GetYear(d),pc.GetMonth(d),pc.GetDayOfMonth(d)));可以使用PersianDateTime:PM>Install-PackagePersianDateTime参考:PersianDateTime如果需要自定义,可以使用string.Split()。添加到其他答案,您可以使用PersianDateTime获得第一个答案:vargregorianDate="Thursday,October24,2013";vardate=DateTime.Parse(gregorianDate);varpersianDate=newPersianDateTime(date);varresult=persianDate.ToString("dddddMMMMyyyy");DateTimedate=newDateTime(2013,10,24);varcalendar=newPersianCalendar();varpersianDate=newDateTime(calendar.GetYear(date),calendar.GetMonth(date),calendar.GetDayOfMonth(date));varresult=persianDate.ToString("yyyyMMMddd",CultureInfo.GetCultureInfo("fa-Ir"));在Windows10中,使用框架4+:Console.WriteLine(Convert.ToDateTime("1392/08/02",newCultureInfo("fa-IR")));或Console.WriteLine(DateTime.Parse("1392/08/02",newCultureInfo("fa-IR")));我推荐使用MD.PersianDateTime,你可以像使用DateTime一样简单地做到这一点:varpersianDateTimeNow=PersianDateTime.Now;persianDateTimeNow.EnglishNumber=true;Console.WriteLine(persianDateTimeNow.ToString());https://github.com/Mds92/MD.PersianDateTime以上是C#学习教程:如何将公历日期转换为波斯日期?全部共享Rong,如果对你有用,需要进一步了解C#学习教程,希望你多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
