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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Persian Date Library
Convert Gregorian (Miladi) dates to Solar Hijri (Shamsi) dates with ease!
Features
- 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
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
- 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 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 | Versions 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 | 157 | 10/3/2024 |
1.3.0 | 126 | 9/12/2024 |
1.2.0 | 105 | 9/12/2024 |
1.0.8 | 105 | 9/12/2024 |
1.0.7 | 97 | 9/12/2024 |
1.0.6 | 110 | 9/12/2024 |
1.0.5 | 99 | 9/12/2024 |
1.0.4 | 350 | 5/16/2023 |
1.0.3 | 155 | 5/16/2023 |
1.0.2 | 959 | 1/24/2020 |
1.0.1 | 457 | 1/24/2020 |
1.0.0 | 545 | 1/23/2020 |
0.0.0-alpha.0.46 | 56 | 9/12/2024 |
0.0.0-alpha.0.45 | 60 | 9/12/2024 |
0.0.0-alpha.0.43 | 59 | 9/12/2024 |
Add support for .Net 8.0