alexanoid
alexanoid

Reputation: 25770

Yii2/PHP date formatter seconds and locale

I use the following Yii2 PHP code to format my date object taking locale into account Class yii\i18n\Formatter:

$formatter->asDatetime($date, 'short');

It produces the following output:

14.07.18, 20:52 
7/14/18, 8:52 PM

I also interested in the seconds, to get something like:

14.07.18, 20:52:32 
7/14/18, 8:52:32 PM

How to achieve this with Yii2 or with pure PHP?

Upvotes: 1

Views: 490

Answers (1)

Patrick Q
Patrick Q

Reputation: 6393

Replace 'short' with 'dd.MM.yy, HH:mm:ss' for the first format and with 'M/dd/yy, h:mm:ss a' for the second format.

See here for the documentation of asDatetime() and here for all formatting options.

Upvotes: 3

Related Questions