Formatting Date time in view in CakePHP 3



I’m using CakePHP 3.4.

I have set my database timezone to UTC. I am from IST Timezone.

To display DateTime in IST Timezone, this is what I’m doing.

<?= $this->Time->format($user->created, \IntlDateFormatter::FULL, null, 'Asia/Kolkata') ?>

and this is Displaying Time as

Sunday, May 28, 2017 at 2:56:21 PM India Standard Time

I want to display Date in below format

May 28, 2017 2:56:21 PM IST

How I can achieve this?


you need set locale so cake change ur date / currency display for all app:

in config/app.php
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'UR_LOCALE_CODE),

in config/bootstrap.php (u must change format for your locale)

 //Enable immutable time objects in the ORM.
 //You can enable default locale format parsing by adding calls
 //to `useLocaleParser()`. This enables the automatic conversion of
 //locale specific date formats. For details see

//Change the preferred class name to the FrozenTime implementation. 

//format chronos
\Cake\I18n\Time::setToStringFormat([IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT]);
\Cake\I18n\Time::setToStringFormat('dd/MM/YYYY HH:mm');
\Cake\I18n\FrozenTime::setToStringFormat('dd/MM/yyyy HH:mm');


\Cake\Database\Type::build('datetime')->useLocaleParser()->setLocaleFormat('dd/MM/yyyy HH:mm');
\Cake\Database\Type::build('timestamp')->useLocaleParser()->setLocaleFormat('dd/MM/yyyy HH:mm');