Introduction
PersianCalendarPlus is a simple wrapper around System.Globalization.PersianCalendar providing extra functionality such as different kinds of date string in Persian and the ability to convert between them.
How Can I Install It?
You can install it using Nuget package manager:
Install-Package <a href="https://www.nuget.org/packages/PersianCalendarPlus/">PersianCalendarPlus</a>
Where Can I Find the Source Code?
PersianCalendarPlus is open source, you can find the source code on Github: PersianCalendarPlus
Usage Example
PerCalPlus.Now()
PerCalPlus.ToShortDateString()
PerCalPlus.ToLongDateString()
PerCalPlus.GetPersianYear()
PerCalPlus.GetPersianYear(1988)
PerCalPlus.GetPersianMonth()
PerCalPlus.GetPersianMonth(2, 21)
PerCalPlus.GetPersianDay()
PerCalPlus.GetPersianDay(1988, 2, 21)
PerCalPlus.GetDaysInPersianMonth(66, 12)
PerCalPlus.GetDaysInPersianYear(66)
PerCalPlus.GetDayOfWeekName()
PerCalPlus.GetDayOfWeekName(DateTime.Now.AddDays(2))
PerCalPlus.GetMonthName()
PerCalPlus.GetMonthName(DateTime.Now.AddDays(21))
PerCalPlus.GregorianDateToPersian(1999, 8, 2)
PerCalPlus.GregorianDateToPersian("5/27/2015 3:14:25 PM")
PerCalPlus.GregorianDateToPersian(DateTime.Now)
PerCalPlus.GregorianDateToPersianLong(DateTime.Now)
PerCalPlus.PersianDateToGregorian(1366, 12, 2)
PerCalPlus.PersianDateToGregorian(1366, 12, 2, 14, 22, 15)
PerCalPlus.PersianDateToGregorian("1366/12/2",
PerCalPlus.DateStringType.ToShortDateString)
PerCalPlus.PersianDateToGregorian("1394/07/13 08:44:28 ب.ظ",
PerCalPlus.DateStringType.Now)
PerCalPlus.PersianDateToGregorian("دوشنبه - 2 اسفند - 1366",
PerCalPlus.DateStringType.ToLongDateString)
PerCalPlus.ShortYearToLongYear(66)
PerCalPlus.ShortYearToLongYear("66")
Converting from Gregorian Date to Persian
There are two methods that you can use for this purpose, if you want short date, you can use one of these three overloads:
PerCalPlus.GregorianDateToPersian(1999, 8, 2)
PerCalPlus.GregorianDateToPersian("5/27/2015 3:14:25 PM")
PerCalPlus.GregorianDateToPersian(DateTime.Now)
If you need long string date, you can use:
PerCalPlus.GregorianDateToPersianLong(DateTime.Now)
Converting from Persian Date to Gregorian
There is one method for this with five overloads, two of them take int as argument:
PerCalPlus.PersianDateToGregorian(1366, 12, 2)
PerCalPlus.PersianDateToGregorian(1366, 12, 2, 14, 22, 15)
The other three take a date string, note that you should specify what kind of date string you're supplying as argument through PerCalPlus.DateStringType enumeration, these three kind of strings are the same as the one created by these three methods:
PerCalPlus.Now()
PerCalPlus.ToShortDateString()
PerCalPlus.ToLongDateString()
In the enum part of method argument, you should specify what kind of date string you want to supply as an argument, these three are PerCalPlus.DateStringType.ToShortDateString and PerCalPlus.DateStringType.Now and PerCalPlus.DateStringType.ToLongDateString which correspond to the aforementioned methods, note that the date string should conform to the format that produced previously by the PersianCalendarPlus or it isn't going to work:
PerCalPlus.PersianDateToGregorian("1366/12/2",
PerCalPlus.DateStringType.ToShortDateString)
PerCalPlus.PersianDateToGregorian("1394/07/13 08:44:28 ب.ظ",
PerCalPlus.DateStringType.Now)
PerCalPlus.PersianDateToGregorian("دوشنبه - 2 اسفند - 1366",
PerCalPlus.DateStringType.ToLongDateString)