如何为 yii2 应用程序获取时间和日期选择器

How to get time and date picker for yii2 application

我正在使用 yii2 框架开发一个网站,我需要将事件时间和日期保存到数据库中,所以我需要日期和时间选择器我有 dosamigos Datepicker 但他们只提供没有时间的日期,感谢所有

,我怎样才能获得日期和时间选择器
<?= $form->field($model, 'date')->widget(
    DatePicker::className(), [
    // inline too, not bad
     'inline' => false, 
     // modify template for custom rendering
    //'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
    'clientOptions' => [
        'autoclose' => true,
        'format' => 'yyyy-mm-dd H-m-s'
    ]
]);?>

使用这个小部件我只得到指定格式的日期但没有时间

使用 yii2-widget-datetimepicker https://github.com/kartik-v/yii2-widget-datetimepicker

use kartik\datetime\DateTimePicker;
echo DateTimePicker::widget([
    'name' => 'dp_1',
    'type' => DateTimePicker::TYPE_INPUT,
    'value' => '2020-02-02 10:10:10',
    'pluginOptions' => [
        'autoclose'=>true,
        'format' => 'yyyy-mm-dd H-m-s'
    ]
]);

您也可以使用 kartik 日期时间选择器:Kartik date time picker read doc here

use kartik\datetime\DateTimePicker;

echo '<label>Start Date/Time</label>';
echo DateTimePicker::widget([
    'name' => 'datetime_10',
    'options' => ['placeholder' => 'Select operating time ...'],
    'convertFormat' => true,
    'pluginOptions' => [
        'format' => 'd-M-Y g:i A',
        'startDate' => '01-Mar-2014 12:00 AM',
        'todayHighlight' => true
    ]
]);