Hijri

Hijri

Hijri DateTime (Islamic).

Moamen Eltouny (Raggi)
PHP Version : >= 7.2 License Support
Source Packagist Version Packagist Downloads

Install

Install the latest version using Composer

composer require pharaonic/php-hijri

Depends on : Carbon

Usage

Inclusion

Using Carbon Mixin to include the Hijri to it.

use Carbon\Carbon;
use Pharaonic\Hijri\HijriCarbon;

Carbon::mixin(HijriCarbon::class);

Getting Hijri

This is how to get Hijri/Gregorian DateTime

$dt = Carbon::now();

echo $dt->isoFormat('LLLL');                // Tuesday, May 25, 2021 7:00 PM
echo $dt->toHijri()->isoFormat('LLLL');     // Tuesday, Shawwal 13, 1442 7:00 PM

echo $dt->format('r');                      // Tue, 25 May 2021 07:00:00 +0000
echo $dt->toHijri()->format('r');           // Tue, 13 Shawwal 1442 07:00:00 +0000

Localization

Using Hijri with multiple languages.

Carbon::setLocale('ar');
echo $dt->toHijri()->isoFormat('LLLL');    // الثلاثاء 13 شوّال 1442 07:00

// OR [Inline]
echo $dt->locale('ar')->toHijri()->isoFormat('LLLL');