1. Go to this page and download the library: Download danialzash/laravel-jalali 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/ */
danialzash / laravel-jalali example snippets
return [
'default_format' => 'datetime', // Options: 'datetime', 'date', 'time', or custom format
];
// Current date/time in Jalali
jalali();
// Convert a specific date
jalali('2024-03-20');
// With custom format
jalali(now(), 'Y/m/d');
// From a Carbon instance
jalali($user->created_at, 'l j F Y');
use Danialzash\LaravelJalali\Facades\Jalali;
// Get a Jalalian instance
$jalaliDate = Jalali::from(now());
// Format directly
$formatted = Jalali::format(now(), 'Y-m-d H:i:s');
use Illuminate\Support\Carbon;
// Get a Jalalian instance from Carbon
$jalali = Carbon::now()->toJalali();
// Get a formatted Jalali string directly
$dateString = Carbon::now()->toJalaliString('Y/m/d');
// Works with any Carbon instance
$user->created_at->toJalaliString(); // e.g., "1402/12/30 14:30:00"