Convert Gregorian (Miladi) dates to Solar Hijri (Shamsi) dates with ease!
- Convert Gregorian dates to Shamsi (Persian) dates
- Support for both
DateTime
andDateTimeOffset
- Get Shamsi year, month, and day components
- Get Shamsi month and day names
- Extension methods for easy conversion
Install the package via NuGet:
dotnet add package PersianDateShamsi
using PersianDate;
PersianDateShamsi persianDate = new PersianDateShamsi();
DateTime now = DateTime.Now;
int shamsiYear = persianDate.GetShamsiYear(now);
string shamsiMonthName = persianDate.GetShamsiMonthName(now);
string shamsiDayString = persianDate.GetShamsiDayString(now);
string shamsiDayName = persianDate.GetShamsiDayName(now);
string shamsiDayShortName = persianDate.GetShamsiDayShortName(now);
Console.WriteLine($"Year: {shamsiYear}");
// Output: Year: 1402
Console.WriteLine($"Month: {shamsiMonthName}");
// Output: Month: فروردین
Console.WriteLine($"Day: {shamsiDayString}");
// Output: Day: 01
Console.WriteLine($"Day Name: {shamsiDayName}");
// Output: Day Name: سهشنبه
Console.WriteLine($"Short Day Name: {shamsiDayShortName}");
// Output: Short Day Name: سه
using PersianDate;
DateTime? dateTime = new DateTime(2023, 10, 5);
DateTimeOffset? dateTimeOffset = new DateTimeOffset(2023, 10, 5, 0, 0, 0, TimeSpan.Zero);
Console.WriteLine(dateTime.ToShamsiDate());
// Output: 1402/07/13
Console.WriteLine(dateTimeOffset.ToShamsiDate());
// Output: 1402/07/13
Console.WriteLine(dateTime.ToShortShamsiDate());
// Output: 02/07/13
Console.WriteLine(dateTimeOffset.ToShortShamsiDate());
// Output: 02/07/13
Console.WriteLine(dateTime.ToLongShamsiDate());
// Output: پنجشنبه 13 مهر 1402
Console.WriteLine(dateTimeOffset.ToLongShamsiDate());
// Output: پنجشنبه 13 مهر 1402
using PersianDate;
ToGregorian toGregorian = new ToGregorian();
int gregorianYear = toGregorian.GetGregorianYear(1402, 1, 1);
DateTime gregorianDate = toGregorian.ToGregorianDate(1402, 1, 1);
int gregorianMonth = toGregorian.GetGregorianMonth(1402, 1, 1);
int gregorianDay = toGregorian.GetGregorianDay(1402, 1, 1);
Console.WriteLine($"Gregorian Year: {gregorianYear}");
// Output: Gregorian Year: 2023
Console.WriteLine($"Gregorian Date: {gregorianDate}");
// Output: Gregorian Date: 2023-03-21
Console.WriteLine($"Gregorian Month: {gregorianMonth}");
// Output: Gregorian Month: 3
Console.WriteLine($"Gregorian Day: {gregorianDay}");
// Output: Gregorian Day: 21
- .NET 8.0
- Install .NET 8.0 SDK
- Clone the repository:
git clone https://github.com/hootanht/PersianDate.git
- Navigate to the project directory:
cd PersianDate
- Restore dependencies:
dotnet restore
- Build the project:
dotnet build
- Run tests:
dotnet test
Version | Changes |
---|---|
1.0.8 | Added support for DateTimeOffset in ToGregorian class and updated PersianDateShamsi.cs and ToShamsi.cs accordingly |
1.0.6 | Added support for .NET 8.0 |
1.0.4 | Added support for .NET 5.0 and 6.0 |
1.0.3 | Changed from .NET Standard 2.0 to .NET 7.0 |
1.0.2 | Improved flexibility |
1.0.1 | Changed from .NET Standard 2.1 to 2.0 for broader platform support |
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please open an issue on GitHub.
Made with ❤️ by Hootan Hemmati