如何从 yii2 中的 dosamigos datepicker 获取当天的名称?

How to get name of the day from dosamigos datepicker in yii2?

这是我为日期选择器编写的代码。我想从日期选择器中获取用户 select 日期的日期。请我是新来的,我需要为我的最后一年项目完成这个。提前谢谢你。

<?= $form->field($model, 'appDate')->widget(
        DatePicker::className(), [
             'inline' => false, 
            'clientOptions' => [
                'autoclose' => true,
                'format' => 'yyyy-m-d'
            ]
]);?>

您必须使用事件来获取所选日期才能获取日期名称。 我使用了 changeDate 事件, 这是代码:

<?= $form->field($model, 'appDate')->widget(
    DatePicker::className(), [
        'inline' => false, 
        'clientOptions' => [
            'autoclose' => true,
            'format' => 'yyyy-m-d',
        ],
        'clientEvents' => [
            'changeDate' => new \yii\web\JsExpression('function(e){var days =["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
                $("#dayname").text(days[e.date.getDay()]); }') ,
        ] ,
    ]);?>

我创建了一个元素来显示日期名称:

<span id="dayname"></span>

输入您的输入:

<?= $form->field($model, 'appDate')->widget(
    DatePicker::className(), [
        'inline' => false, 
        'clientOptions' => [
            'autoclose' => true,
            'format' => 'yyyy-m-d',
        ],
        'clientEvents' => [
            'changeDate' => new \yii\web\JsExpression('function(e){var days =["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
                $("#appointment-appday").val(days[e.date.getDay()]); }') ,
        ] ,
    ]);?>