word1018808441 2015-04-29 12:38:43 19044次浏览 6条评论 6 1 0

昨天下了一个yii的日期插件,叫做 yii2-date-picker-widget 但是是英文的,我今天研究了下,发现它的语言默认是en,在bootstrap-datepicker.js文件里面也只有一个 en 的英文,我就在里面直接复制这个 en ,加在 en 的后面改名 zh 再把里面改成中文,调用这个插件的时候,设置它的语言为 zh 就好了,

var dates = $.fn.datepicker.dates = {
en: {
    days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
    daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
    daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
    months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
    monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
    today: "Today",
    clear: "Clear"
},
zh: {
    days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
    daysShort: ["日", "一", "二", "三", "四", "五", "六", "日"],
    daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
    months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    today: "Today",
    clear: "Clear"
}
};
<?php 
$form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= DatePicker::widget([
    'model' => $model,
    'attribute' => 'create_time',
    'template' => '{addon}{input}',
    'clientOptions' => [
        'autoclose' => true,
        'format' => 'yyyy-mm-dd',
        'language'=>'zh'
    ]
]);?>
觉得很赞
  • 评论于 2015-05-13 14:27 举报

    请问使用composer下载该插件需要**吗

    1 条回复
    评论于 2015-05-13 14:56 回复

    用composer是要翻的

  • 评论于 2015-05-13 15:53 举报

    我不是用composer安装的 我下载了一个DatePicker 放在widgets文件下 用不了 帮我看看是哪方面的原因?

  • 评论于 2015-05-20 14:55 举报

    可以设置时分秒的格式吗,该如何设置

  • 评论于 2015-07-27 11:26 举报

    其实看源码之后我就知道怎么设置了,没必要像你哪样啊。

    前提是必须安装这个插件: 具体看readme
    php composer.phar require "2amigos/yii2-date-picker-widget":"*"

        use dosamigos\datepicker\DatePicker;
        <?= $form->field($model, 'start_time')->widget(
            DatePicker::className(), [
            // inline too, not bad
            'inline' => true,
            'language' => 'zh-CN' , //--设置为中文
            'clientOptions' => [
                'autoclose' => false,
                'format' => 'yyyy-mm-dd'
            ]
        ]);?>
    
    2 条回复
    评论于 2016-10-18 15:23 回复

    您的这个composer命令我执行不了

    评论于 2018-04-11 16:02 回复

    使用 composer require "2amigos/yii2-date-picker-widget":"*"
    环境变量配置好的情况下 php composer.phar = composer

    , , 觉得很赞
  • 评论于 2016-08-11 12:06 举报

    怎么让插件只能选择年月,不要选择日

  • 评论于 2017-05-04 12:20 举报

    关于jui日历问题,就是两个input框,第一个为开始日期,第二个位结束日期(作用就是要在筛选的时候,让用户选出一个时间段出来),那么问题来了,在yii2里面用DatePicker::widget的这种方法,怎么才能做到,第二个input框的值不能小于第一个input框的值呢?

    备注:在jqueyrui中是这样做的:

    $( "#from" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#to" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
    

    });

    那在yii2中,怎么要怎么做呢?求解rili.png

    1 条回复
    评论于 2017-06-28 10:25 回复

    你这个问题解决了吗 我也遇到了

    觉得很赞
您需要登录后才可以评论。登录 | 立即注册