PHP code example of natilosir / jalali

1. Go to this page and download the library: Download natilosir/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/ */

    

natilosir / jalali example snippets



use natilosir\jalali\time;

// 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;

$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;

time::Timezone(3.5); // tehran

$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

$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

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

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

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