Format date in the indexSuccess.php

后端 未结 4 1629
礼貌的吻别
礼貌的吻别 2021-01-20 14:53

I want to format the created_at field date from the original for something like 03.May.2011 to be shown in the indexSuccess.php and in the sh

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 15:34

    I believe the date is returned in a string format Y-m-d H:i:s, as fits the MySQL datetime type. It would be nicest to convert this to a PHP DateTime instance using DateTime::createFromFormat, presuming you are using PHP > 5.3.

    So, in your controller:

    $this->creation_date = DateTime::createFromFormat('Y-m-d H:i:s', $item->created_at);
    

    Then, in your view:

    format('d.F.Y') ?>
    

    See also DateTime::format


    If you are using PHP 5.2 or before, you can't use createFromFormat. You probably want to fall back on strtotime:

    $this->creation_date = strtotime($this->created_at);
    

    and in the view:

    
    

提交回复
热议问题