PHPackages                             natilosir/jalali - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. natilosir/jalali

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

natilosir/jalali
================

A simple PHP library for managing Jalali (Shamsi) dates.

1.0.4(1y ago)1382MITPHP

Since Dec 15Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/natilosir/Jalali)[ Packagist](https://packagist.org/packages/natilosir/jalali)[ RSS](/packages/natilosir-jalali/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (6)Used By (2)

Jalali Date Converter
=====================

[](#jalali-date-converter)

This library helps you convert dates between the Gregorian (Miladi) and Jalali (Persian) calendars in PHP. Below are some examples of how to use the library.

### Install

[](#install)

```
composer require natilosir/Jalali
```

Alternatively, you can clone the repository directly:

```
git clone https://github.com/natilosir/Jalali
```

##### Use

[](#use)

```
require __DIR__ . '/vendor/autoload.php';
use natilosir\jalali\time;
```

### Example Usage

[](#example-usage)

1. **Set the Timezone to Tehran**
    You can set the timezone to Tehran (UTC+3.5) using the `Timezone` method.
2. **Convert Timestamp to Jalali Date**
    Convert a Unix timestamp to a Jalali date using the `toj` method.
3. **Modify the Jalali Date**
    You can modify a Jalali date by adding hours, days, months, or years using the `addH`, `addD`, `addM`, and `addY` methods.
4. **Format the Date in Persian**
    Use the `format` method to display the date in Persian format.
5. **Convert Jalali Date to Timestamp**
    You can convert a Jalali date string to a Unix timestamp using the `tot` method.
6. **Convert Jalali Date to Gregorian**
    Use the `miladi` method to convert a Jalali date to its Gregorian counterpart.

---

Supported Placeholders
----------------------

[](#supported-placeholders)

PlaceholderDescriptionExample`y`Last two digits of the Jalali year`03``Y`Full Jalali year`1403``m`Numeric representation of the Jalali month`09``M`Name of the Jalali month (in Persian)`آذر``d`Numeric representation of the Jalali day`25``D`Day suffix (in Persian)`بیست‌و‌پنجم``W`Day of the week (in Persian)`یک‌شنبه``h`Hour in 12-hour format`06``H`Hour in 24-hour format`18``i`Minutes`33``s`Seconds`36`---

Example Usage
-------------

[](#example-usage-1)

```
// Set timezone offset (e.g., Iran Standard Time)
time::Timezone(3.5);

// Define a Gregorian timestamp
$timestamp = time();

// Format the Jalali date
$formattedDate = time::format($timestamp, 'W D M Y h:i:s');
// OR
$formattedDate = time::format('W D M Y h:i:s');

// Output: یک‌شنبه بیست‌و‌پنجم آذر 1403 06:33:36
echo $formattedDate;
```

---

Placeholders in Action
----------------------

[](#placeholders-in-action)

Given:

- Jalali date: `1403/09/25`
- Gregorian timestamp: `2024-12-15 06:33:36`

Using the format string `'W D M Y h:i:s'`, the replacements are:

```
$timestamp = strtotime('2024-12-15 06:33:36');
$formattedDate = time::format($timestamp, 'W D M Y h:i:s');
// OR
$formattedDate = time::format('W D M Y h:i:s');

// Output: یک‌شنبه بیست‌و‌پنجم آذر 1403 06:33:36
echo $formattedDate;
```

---

### Code Example

[](#code-example)

Set the timezone to Tehran

```
time::Timezone(3.5); // tehran
```

Convert timestamp to Jalali date

```
$timestamp  = time();
$jalaliDate = time::toj($timestamp, 'Y/m/d h:i:s');
// OR
$jalaliDate = time::toj('Y/m/d h:i:s');

echo "Jalali Date: {$jalaliDate}\n"; // Jalali Date: 1403/09/24 23:24:01
```

Modify the Jalali date

```
$modifiedDate = time::toj($timestamp)->addH(2)->addD(3)->addM(4)->addY(5);
echo "Modified Jalali Date: {$modifiedDate}\n"; // Modified Jalali Date: 1409/01/28 01:24:01
```

Format the date in Persian

```
echo time::format($timestamp, 'W D M Y h:i:s'); // Jalali Date: یک‌شنبه بیست‌و‌پنجم آذر 1403 10:25:46
```

Convert Jalali date to timestamp

```
$jalaliDateInput    = '1402/09/24 14:30:00';
$convertedTimestamp = time::tot($jalaliDateInput);
echo "Timestamp: $convertedTimestamp\n"; // Timestamp: 1702638000
```

Convert Jalali date to Gregorian using the miladi method

```
echo time::miladi('1401/05/24 14:12:32'); // 2022-08-15 10:42:32
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance53

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

5

Last Release

467d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab074f478dbfd74f8f693edecac575b69c1e42087aaa44343cc1b45c43c23059?d=identicon)[natilosir](/maintainers/natilosir)

---

Top Contributors

[![natilosir](https://avatars.githubusercontent.com/u/182812192?v=4)](https://github.com/natilosir "natilosir (3 commits)")

### Embed Badge

![Health badge](/badges/natilosir-jalali/health.svg)

```
[![Health](https://phpackages.com/badges/natilosir-jalali/health.svg)](https://phpackages.com/packages/natilosir-jalali)
```

###  Alternatives

[spiral/mcp-server

Spiral bridge for MCP server

541.1k2](/packages/spiral-mcp-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
