Home > other >  How to change datetime format to another language PHP
How to change datetime format to another language PHP

Time:01-20

I am working with Php and right now i am getting date in following format

21 Dec 22  14:13

And i want to convert this date time into arabic language format,expected output is

 ٢١ ديسمبر ٢٢:١٣

Can we do this without "google api",How can i do this with php ?

CodePudding user response:

PHP has everything you need for date formatting. Using IntlDateFormatter:

<?php
$date = '21 Dec 22  14:13';
$date_time = new DateTime($date);

$formatter = new IntlDateFormatter(
    'ar_DZ',
);
print $formatter->format($date_time);

Refer the IntlDateFormatter docs.

CodePudding user response:

many of suggestion say you have to set setlocale but setlocale won't actually do any language translation for you but rather affects things like the formatting and comparator functionality. If you want localisation then you could try using IntlDateFormatter which may give you what you need.

  • Related