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
To enable the Persian calendar, go into Settings, click on the General tab, and select it as an Alternate calendar.
For example, January 1, 2022 fell in year 1400 in the Solar Hijri calendar, which corresponds to year 1443 in the Hijri calendar.
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)));
You can use PersianDateTime:
PM> Install-Package PersianDateTime
The Reference: PersianDateTime
You can use string.Split()
if you need customization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With