MiladiToPersianConverter 1.1.0
dotnet add package MiladiToPersianConverter --version 1.1.0
NuGet\Install-Package MiladiToPersianConverter -Version 1.1.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="MiladiToPersianConverter" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiladiToPersianConverter" Version="1.1.0" />
<PackageReference Include="MiladiToPersianConverter" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MiladiToPersianConverter --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MiladiToPersianConverter, 1.1.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.
#:package MiladiToPersianConverter@1.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MiladiToPersianConverter&version=1.1.0
#tool nuget:?package=MiladiToPersianConverter&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MiladiToPersianConverter
A comprehensive .NET library for converting between Gregorian (Miladi) and Persian (Shamsi/Jalali) calendar dates with extensive formatting options.
Table of Contents
Features
- ⏳ Bidirectional conversion between Gregorian and Persian calendars
- 🎨 Multiple formatting options:
- Compact date strings (
YYYYMMDD) - Datetime with hours and minutes (
YYYYMMDDHHmm) - Full datetime with seconds (
YYYYMMDDHHmmss) - Human-readable formats with Persian month names
- Compact date strings (
- 🔧 Utility methods for:
- Adding separators (slashes/dashes) to dates
- Formatting time strings
- Getting Persian day/month names
- Unix timestamp conversion
- 🛡️ Error handling with fallback to current datetime
Installation
NuGet Package Manager
Install-Package MiladiToPersianConverter
Package Reference
<PackageReference Include="MiladiToPersianConverter" Version="1.0.0" />
Usage
Basic Conversion
using MiladiToPersianConverter;
// Convert current date to Persian
DateTime now = DateTime.Now;
string persianDate = now.MiladiToPersian(); // "14020225"
string persianWithTime = now.MiladiToPersianWithMinutes(); // "140202251430"
string persianFull = now.MiladiToPersianWithSeconds(); // "14020225143015"
string withMonthName = now.MiladiToPersianWithMonthName(); // "25 اردیبهشت 1402"
Formatting Helpers
// Format date strings
string withSlashes = "14020225".SetDateSlash(); // "1402/02/25"
string withDashes = "14020225".SetDateDash(); // "1402-02-25"
// Format time strings
string formattedTime = "1425".SetTimeSeparate(); // "14:25"
string fullTime = "142533".SetTimeSeparate(); // "14:25:33"
// Combined datetime formatting
string formattedDT = "140202251430".SetDateTimeSeprator(); // "14:30 - 1402/02/25"
Reverse Conversion
// Persian to Gregorian conversion
DateTime fromPersianDate = "14020225".PersianToMiladi();
DateTime fromPersianDateTime = "140202251430".PersianToMiladiDateTime();
Utility Methods
// Get Persian names
string dayName = DayOfWeek.Friday.GetPersianDayOfWeek(); // "جمعه"
string monthName = 7.GetPersianMounth(); // "مهر"
// Unix timestamp
double unixTime = DateTime.Now.ToUnixTimeStamp(3.5); // Tehran timezone
Code Examples
Complete Conversion Example
using System;
using MiladiToPersianConverter;
class Program
{
static void Main()
{
// Gregorian to Persian
DateTime gregorianDate = new DateTime(2023, 5, 15, 14, 30, 0);
Console.WriteLine(gregorianDate.MiladiToPersian()); // "14020225"
Console.WriteLine(gregorianDate.MiladiToPersianWithMonthName()); // "25 اردیبهشت 1402"
// Persian to Gregorian
DateTime convertedBack = "14020225".PersianToMiladi();
Console.WriteLine(convertedBack.ToString("yyyy-MM-dd")); // "2023-05-15"
// Formatting
Console.WriteLine("140202251430".SetDateTimeSeprator()); // "14:30 - 1402/02/25"
}
}
Error Handling Example
try
{
DateTime invalidConversion = "invalid".PersianToMiladi();
}
catch
{
// Falls back to DateTime.Now
Console.WriteLine("Conversion failed, using current date");
}
Support
Found a bug or need help? Open an issue on GitHub.
For quick questions, you can email: jebaleali@gmail.com
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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.