Kokesh
Kokesh

Reputation: 1

Translate names of the month

I am using OOP PHP DateTime and I want to post month name in three letters like so

$EventDate = new DateTime(DATEDATA);
echo $EventDate -> format('M');

This is code for what I need, but for example if the DATEDATA will be december it will echo out DEC but I want this DEC to translate in my language and instead of DEC to echo დეკ. Can someone explain how it is possible how to translate this kind of things manually?

Thanks in advnace.

Upvotes: 0

Views: 740

Answers (1)

salathe
salathe

Reputation: 51970

The IntlDateFormatter class contains the IntlDateFormatter::formatObject() method, which offers a quick way of formatting a DateTime object using a specified locale.

As an example, let's format a DateTime object for December 12th, 2017 as an abbreviated month name in Georgian.

$datetime = new DateTime("2017-12-12");
$month = IntlDateFormatter::formatObject($datetime, "MMM", "ka");
echo $month;

The above example outputs the following, as expected:

დეკ

Upvotes: 4

Related Questions