Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 776
JAC Avatar asked Jun 06 '15 13:06

JAC


People also ask

How do I change a calendar to Persian?

To enable the Persian calendar, go into Settings, click on the General tab, and select it as an Alternate calendar.

What year is 2022 in the Persian calendar?

For example, January 1, 2022 fell in year 1400 in the Solar Hijri calendar, which corresponds to year 1443 in the Hijri calendar.


2 Answers

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))); 
like image 133
Alioza Avatar answered Sep 29 '22 00:09

Alioza


You can use PersianDateTime:

PM> Install-Package PersianDateTime 

The Reference: PersianDateTime

You can use string.Split() if you need customization.

like image 32
Elnaz Avatar answered Sep 28 '22 23:09

Elnaz