PHP code example of hussainweb / date-converter

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

    

hussainweb / date-converter example snippets


// Ensure you have: 
// use Hussainweb\DateConverter\Algorithm\GregorianAlgorithm;
// use Hussainweb\DateConverter\Value\GregorianDate;

$gregorianAlgo = new GregorianAlgorithm();

// Convert Julian Day to Gregorian Date
// Example Julian Day: 2451545 (corresponds to 2000-01-01 Gregorian)
$gregorianDate = $gregorianAlgo->fromJulianDay(2451545);
echo "Gregorian Date: Day=" . $gregorianDate->getMonthDay() . ", Month=" . $gregorianDate->getMonth() . ", Year=" . $gregorianDate->getYear() . "\n";

// Convert Gregorian Date to Julian Day
$dateToConvert = new GregorianDate(1, 1, 2000); // Day, Month, Year
$julianDay = $gregorianAlgo->toJulianDay($dateToConvert);
echo "Julian Day: " . $julianDay . "\n";

// Ensure you have:
// use Hussainweb\DateConverter\Algorithm\Hijri\HijriFatimidAstronomical;
// use Hussainweb\DateConverter\Value\HijriDate;

$hijriAlgo = new HijriFatimidAstronomical();

// Convert Julian Day to Hijri Date
// Example Julian Day: 2457198 (corresponds to 8-9-1436 Hijri Fatimid Astronomical)
$hijriDate = $hijriAlgo->fromJulianDay(2457198);
echo "Hijri Date: Day=" . $hijriDate->getMonthDay() . ", Month=" . $hijriDate->getMonth() . ", Year=" . $hijriDate->getYear() . "\n";

// Convert Hijri Date to Julian Day
$dateToConvert = new HijriDate(8, 9, 1436, $hijriAlgo); // Day, Month, Year, Algorithm instance
$julianDay = $hijriAlgo->toJulianDay($dateToConvert);
echo "Julian Day: " . $julianDay . "\n";

// Ensure you have:
// use Hussainweb\DateConverter\Algorithm\NativeAlgorithm;
// use Hussainweb\DateConverter\Value\NativeDate;

$nativeAlgo = new NativeAlgorithm();

// Convert Julian Day to Native Date (Unix Timestamp)
// Example Julian Day: 2440588 (corresponds to Unix timestamp 0 -> 1970-01-01 00:00:00 UTC)
$nativeDate = $nativeAlgo->fromJulianDay(2440588);
echo "Native Date (Unix Timestamp): " . $nativeDate->getTimeStamp() . "\n";

// Convert Native Date (from Unix timestamp) to Julian Day
$timestamp = 0; // Example: 1970-01-01 00:00:00 UTC
$dateToConvert = new NativeDate($timestamp);
$julianDay = $nativeAlgo->toJulianDay($dateToConvert);
echo "Julian Day: " . $julianDay . "\n";