PersianDateShamsi 1.8.0

dotnet add package PersianDateShamsi --version 1.8.0                
NuGet\Install-Package PersianDateShamsi -Version 1.8.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PersianDateShamsi" Version="1.8.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PersianDateShamsi --version 1.8.0                
#r "nuget: PersianDateShamsi, 1.8.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PersianDateShamsi as a Cake Addin
#addin nuget:?package=PersianDateShamsi&version=1.8.0

// Install PersianDateShamsi as a Cake Tool
#tool nuget:?package=PersianDateShamsi&version=1.8.0                

Persian Date Library

Persian Date Library

Convert Gregorian (Miladi) dates to Solar Hijri (Shamsi) dates with ease!

NuGet NuGet downloads Build Status Build Status

Features

  • Convert Gregorian dates to Shamsi (Persian) dates
  • Support for both DateTime and DateTimeOffset
  • Get Shamsi year, month, and day components
  • Get Shamsi month and day names
  • Extension methods for easy conversion

Installation

Install the package via NuGet:

dotnet add package PersianDateShamsi

Usage

Basic Conversion

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: سه‌

Extension Methods

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

Converting to Gregorian

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

Supported Platforms

  • .NET 8.0

Getting Started

  1. Install .NET 8.0 SDK
  2. Clone the repository:
    git clone https://github.com/hootanht/PersianDate.git
    
  3. Navigate to the project directory:
    cd PersianDate
    
  4. Restore dependencies:
    dotnet restore
    
  5. Build the project:
    dotnet build
    
  6. Run tests:
    dotnet test
    

Version History

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please open an issue on GitHub.


Made with ❤️ by Hootan Hemmati

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.8.0 134 10/3/2024
1.3.0 114 9/12/2024
1.2.0 96 9/12/2024
1.0.8 100 9/12/2024
1.0.7 90 9/12/2024
1.0.6 98 9/12/2024
1.0.5 94 9/12/2024
1.0.4 345 5/16/2023
1.0.3 153 5/16/2023
1.0.2 953 1/24/2020
1.0.1 451 1/24/2020
1.0.0 539 1/23/2020
0.0.0-alpha.0.46 51 9/12/2024
0.0.0-alpha.0.45 59 9/12/2024
0.0.0-alpha.0.43 54 9/12/2024

Add support for .Net 8.0