What I need is to get, date like, 15 march 2014 but in my language. Is there any easy built-in way to translate date function that whenever I use
date("j F Y");
I get something like 15 march 2014 in my language?
BTW I need Azerbaijani translation. Maybe php already has built-in date-time languages.
sudo locale-gen az_AZ and sudo locale-gen az_AZ.UT8 on ubuntu serversetlocale(LC_ALL, "az-AZ"); or setlocale(LC_TIME, "az-AZ"); and all variations of az-AZ, aze, az_AZ on php file. No success!What am I doing wrong?
You may use php_intl extension if it is on.
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
exit ('IntlDateFormatter is available on PHP 5.3.0 or later.');
}
if (!class_exists('IntlDateFormatter')) {
exit ('You need to install php_intl extension.');
}
$fullDateFormatter = new IntlDateFormatter(
'az_AZ',
IntlDateFormatter::FULL,
IntlDateFormatter::NONE
);
$longDateFormatter = new IntlDateFormatter(
'az_AZ',
IntlDateFormatter::LONG,
IntlDateFormatter::NONE
);
$shortDateFormatter = new IntlDateFormatter(
'az_AZ',
IntlDateFormatter::SHORT,
IntlDateFormatter::NONE
);
$customDateFormatter = new IntlDateFormatter(
'az_AZ',
IntlDateFormatter::NONE,
IntlDateFormatter::NONE,
date_default_timezone_get(),
IntlDateFormatter::GREGORIAN,
'dd MMMM yyyy'
);
$datetime = new DateTime("2014-03-15 11:22:33");
echo $fullDateFormatter->format($datetime) . "\n";
echo $longDateFormatter->format($datetime) . "\n";
echo $shortDateFormatter->format($datetime) . "\n";
echo $customDateFormatter->format($datetime) . "\n";
The results are,
şənbə, 15, Mart, 2014
15 Mart , 2014
2014-03-15
15 Mart 2014
Use setlocale(LC_TIME, 'your locale').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With