douyou2234 2014-11-21 19:35
浏览 67

格式化时间小部件ActiveForm yii2

Good afternoon I need to format the input of a time type field in the widget active form, my form should be short time without the seconds, the field is defined in the table of type time, is there any way to tell it to the widget actiform or model this field is of format "php: h: i".

Thank you very much,

Wilmer.

<?= $form->field($model, 'turnos008')->textInput(['class' => 'form-control col-md-2 inicio']) ?>
  • 写回答

2条回答 默认 最新

  • dsfe167834 2014-11-22 22:16
    关注

    Before rendering your field(In Controller for example), you can do like below:

    I assumed that the time is 12:20:21 AM

    //for example: output is : 12:20 AM
    $model->turnos008=Yii::$app->formatter->asTime($model->turnos008, 'short');
    
    //for example: output is : 12:20:21 AM
    $model->turnos008=Yii::$app->formatter->asTime($model->turnos008, 'medium');
    
    //for example: output is : 12:20:21 AM GMT
    $model->turnos008=Yii::$app->formatter->asTime($model->turnos008, 'long');
    
    //for example: output is : 12:20
    $model->turnos008=Yii::$app->formatter->asTime($model->turnos008, 'php:h:i');
    

    You may take a look at Yii2's official document on http://www.yiiframework.com/doc-2.0/yii-i18n-formatter.html#asTime()-detail

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序