我如何在yii2时间选择器小部件中获得默认时间


How can I get default Time in yii2 Timepicker Widget?

显示当前时间为默认时间,验证工作。但是,我想要自定义默认时间。

下面是我的代码:
<?= $form->field($model, 'e_start_time')->widget(TimePicker::className(),  
     [
        'readonly' => true,                     
        'pluginOptions' => [
                'minuteStep' => 5,
                'showMeridian' => true,
        ],
        'options'=>[
            'class'=>'form-control',
        ],
    ]); ?>

试试这个。因此,您可以使用date('H:i', strtotime('-2 hour')date('H:i', strtotime('+2 hour'))'00:00'作为'defaultTime'

<?= $form->field($model, 'e_start_time')->widget(TimePicker::className(),  
     [
        'readonly' => true,                     
        'pluginOptions' => [
                'minuteStep' => 5,
                'showMeridian' => false,
                'defaultTime' => date('H:i', strtotime('-2 hour')),
        ],
        'options'=>[
            'class'=>'form-control',
        ],
    ]); ?>