>我正在使用 Yii2 框架开发一个网站,他们需要将事件时间和日期保存到数据库中,所以我需要日期和时间选择器我得到了 dosamigos 日期选择器,但他们只给出日期而没有时间,我如何获得日期和时间选择器,感谢所有人
<?= $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 kartikdatetimeDateTimePicker;
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日期时间选择器在此处阅读文档
use kartikdatetimeDateTimePicker;
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
]
]);