Persia.NET Component

Persian Calendar and Localization Library for .NET

Persia.NET Component Logo
Persia.NET: A comprehensive Persian calendar and localization library for .NET applications.

Archive Notice: This is a historical documentation page for the Persia.NET component. While newer versions and alternatives may be available, this page is maintained to preserve references from NuGet package Persia.NET 3.0.4727.

Overview

Persia.NET is a comprehensive library for Persian (Jalali) calendar support and localization in .NET applications. It provides tools for converting between Gregorian and Persian dates, formatting dates according to Persian culture, and supporting Persian text in Windows Forms and ASP.NET applications.

Latest Version

3.0.4727

NuGet Package

Persia.NET

Framework Support

.NET Framework 2.0+

Key Features

  • Persian Calendar Implementation: Complete implementation of the Persian (Jalali) calendar system
  • Date Conversion: Convert between Gregorian and Persian dates with ease
  • Persian Culture Support: CultureInfo implementation for fa-IR locale
  • Date Formatting: Format dates according to Persian conventions
  • UI Controls: Persian-enabled date picker and calendar controls
  • Localization Tools: Utilities for localizing applications for Persian-speaking users
  • Number Formatting: Convert numbers to Persian text representation

Installation

The recommended way to install Persia.NET is through NuGet Package Manager:

Install-Package Persia.NET

Alternatively, you can download the assembly and reference it manually in your project.

Basic Usage

Converting Dates

Converting between Gregorian and Persian dates is straightforward:


// Convert from Gregorian to Persian
DateTime gregorianDate = DateTime.Now;
PersianDate persianDate = PersianDate.FromGregorianDate(gregorianDate);

// Display Persian date components
Console.WriteLine($"Persian Year: {persianDate.Year}");
Console.WriteLine($"Persian Month: {persianDate.Month}");
Console.WriteLine($"Persian Day: {persianDate.Day}");

// Convert back to Gregorian
DateTime convertedBack = persianDate.ToGregorianDate();

Formatting Dates

Format dates according to Persian conventions:


// Format a Persian date as a string
PersianDate today = PersianDate.Today;
string formatted = today.ToString("yyyy/MM/dd"); // e.g., 1389/06/25

// Using the Persian culture for formatting
CultureInfo persianCulture = new CultureInfo("fa-IR");
persianCulture.DateTimeFormat.Calendar = new PersianCalendar();
string longDate = today.ToDateTime().ToString("D", persianCulture);

Using UI Controls

Persia.NET provides UI controls for Windows Forms applications:


// Add a Persian DatePicker to your form
PersianDatePicker datePicker = new PersianDatePicker();
datePicker.Location = new Point(50, 50);
this.Controls.Add(datePicker);

// Handle date selection
datePicker.DateChanged += (sender, e) => {
    PersianDate selected = datePicker.SelectedDate;
    MessageBox.Show($"Selected date: {selected}");
};
Persia.NET DatePicker Control
The Persian DatePicker control in a Windows Forms application.

Advanced Features

Number to Text Conversion

Convert numeric values to their Persian text representation:


// Convert number to Persian text
string text = PersianNumberConverter.Convert(1234567);
// Output: یک میلیون و دویست و سی و چهار هزار و پانصد و شصت و هفت

Custom Date Formats

Create custom date formats for specific application needs:


// Custom format with Persian month names
PersianDate date = PersianDate.Today;
string custom = date.ToString("d MMMM yyyy");
// Example output: 25 شهریور 1389

ASP.NET Integration

Use Persia.NET in ASP.NET applications:


// In your ASPX page
<asp:TextBox runat="server" ID="txtDate" />
<persia:PersianCalendarExtender runat="server" 
    TargetControlID="txtDate" />

// In your code-behind
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        txtDate.Text = PersianDate.Today.ToString();
    }
}

System Requirements

  • .NET Framework 2.0 or higher
  • Windows XP/Vista/7/8/10 for Windows Forms controls
  • ASP.NET 2.0 or higher for web controls

License

Persia.NET is distributed under the MIT License, which allows for both personal and commercial use with minimal restrictions.

Support and Resources

For more information and support, please visit:

Persia.NET has been a cornerstone component for Persian localization in .NET applications since its introduction. While newer alternatives may be available, this documentation is maintained for historical reference and to support existing implementations.