Search code examples
phpdateintlhijri

Incorrect Hijri date in PHP Intl


Today is 27 Ramadan 1438 in Asia/Tehran. but PHP Intl says today is 28 Ramadan 1438. Anyone know what the problem is?

$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
                    'en_US@calendar=islamic',
                    IntlDateFormatter::FULL,
                    IntlDateFormatter::FULL,
                    'Asia/Tehran',
                    IntlDateFormatter::TRADITIONAL);

echo $IntlDateFormatter->format($DateTime);

Solution

  • try this: (changed calender from islamic to islamic-civil)

    $DateTime = new DateTime();
    $IntlDateFormatter = new IntlDateFormatter(
                        'en_US@calendar=islamic-civil',
                        IntlDateFormatter::FULL,
                        IntlDateFormatter::FULL,
                        'Asia/Tehran',
                        IntlDateFormatter::TRADITIONAL);
    
    echo $IntlDateFormatter->format($DateTime);