doujiayuan8415 2017-03-30 04:49
浏览 207

如何在Yii2中格式化数据库中的日期

If I have function like this

protected function getAreaValues($model)
    {
        return 
        [
            [
                $model->getAttributeLabel('EXPDATE'),TbArea::findOne($model->KODE)->EXPDATE
            ],  

        ];
    }

where EXPDATE IS date data

How to format it in d-M-Y ?

I add formatter in web.php in config like this

        'formatter' => [
            'class' => 'yii\i18n\Formatter',
            'nullDisplay' => '-',
            'dateFormat' => 'd-M-Y',
            'datetimeFormat' => 'd-M-Y H:i:s',
            'timeFormat' => 'H:i:s',         
        ],

But still not working

</div>
  • 写回答

2条回答 默认 最新

  • dscc90150010 2017-03-30 05:22
    关注

    You can format date like below.

    echo Yii::$app->formatter->asDate('2017-03-30', 'd-M-Y'); // 30-Mar-2017
    

    try this.

    and you can check Yii2 doc

    Yii2 Formatters

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题