0

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>
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154

1 Answers1

1

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.

jspit
  • 7,276
  • 1
  • 9
  • 17
  • Thank you for your answer. But I don't want to give the date manually. The date is taken from the WordPress post in the following code: `$date = get_post_meta($id, 'edgtf_match_date_meta', true);` – Sib Themes Jul 24 '23 at 22:14
  • The code you show is not reproducible for other programmers without your specific Wordpress environment. new DateTime creates a DateTime object. If I interpret your code correctly then $dateobj is just such a DateTime object which you can use instead of $DateTime. – jspit Jul 26 '23 at 17:54