Converting the Gregorian date to Jalali

220 views Asked by At

The PHP code displays the date as 25 July 2023. I want this date to become jalali

$id = get_the_ID();

$date = get_post_meta($id, 'edgtf_match_date_meta', true);
$dateobj = date_create_from_format('Y-m-d', $date);
$date = date_format($dateobj, 'j F Y ');
$time = get_post_meta($id, 'edgtf_match_time_meta', true); ?>

<span class="edgtf-match-date"> <?php echo esc_attr($date) ?>, <?php echo esc_attr($time) ?></span>
1

There are 1 answers

2
jspit On

You can use the IntlDateFormatter class.

$DateTime = new DateTime("2023-07-25");

$IntlDateFormatter = new IntlDateFormatter(
    'ir_IR@calendar=persian',
    IntlDateFormatter::NONE, 
    IntlDateFormatter::NONE,
    NULL,
    IntlDateFormatter::TRADITIONAL,
    "MMMM d, yyyy"
);

echo $IntlDateFormatter->format($DateTime);  //Mordad 3, 1402

For the date format see ICU-Format. "MMMM d, yyyy" is an example.