CakePHP | Date format translation using internationalization

|
| By Webner

In Cakephp, To translate the application language into another, we use internationalization and localization. To display the correct translated date string on change of locale, we need to use right classes.

use Cake\I18n\I18n;
use Cake\I18n\Time;

I18n::Locale('es’'); // es locale is for Spanish
$date = ‘2017-08-29 23:00:00’;
$createdDate = $date->i18nFormat('MMM d, YYY');
echo $createdDate; // Displays ago. 29, 2017 in spanish 
// By default Spanish month displays in lowercase

If we use Default Locale i.e. English then $createdDate displays – Aug 29, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *