PHP code example of sdo-sa / hijri-converter

1. Go to this page and download the library: Download sdo-sa/hijri-converter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sdo-sa / hijri-converter example snippets


use SDOSA\Hijri;

$h = Hijri::toHijri('1982-12-02');   // accepts string, DateTime, or Carbon
echo $h->toIso();                    // 1403-02-17
echo $h->format();                   // 17/02/1403
echo $h->monthName();                // صفر   (default locale is "ar")
echo $h->monthName('en');            // Safar
echo $h->dayName();                  // الخميس

$g = Hijri::toGregorian('1403-02-17');
echo $g->toIso();                    // 1982-12-02

Hijri::today();                      // HijriDate for today

use SDOSA\GregorianDate;
use SDOSA\HijriDate;

GregorianDate::make(1982, 12, 2)->toHijri();       // HijriDate
HijriDate::make(1403, 2, 17)->toGregorian();       // GregorianDate

GregorianDate::fromString('1982-12-02');
HijriDate::fromString('1403-02-17');
GregorianDate::fromDateTime(new DateTimeImmutable); // any DateTime / Carbon

Hijri::toHijri('2024-03-11')->monthName('tr');  // Ramazan
Hijri::toHijri('2024-03-11')->monthName('bn');  // রমজান

use SDOSA\Locales\LocaleRegistry;

LocaleRegistry::setDefault('en');

use SDOSA\Hijri;
use Carbon\Carbon;

Hijri::toHijri(Carbon::now());     // accepts Carbon / DateTime
Carbon::now()->toHijri();          // HijriDate (macro)
Carbon::now()->hijriFormat('-');   // e.g. 01-09-1445 (macro)
bash
php artisan vendor:publish --tag=hijri-config