yii2日期选择控件设置语言 [ 2.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'
]
]);?>
word1018808441 重庆
注册时间:2015-03-24
最后登录:2018-07-04
在线时长:629小时49分
最后登录:2018-07-04
在线时长:629小时49分
- 粉丝49
- 金钱7395
- 威望40
- 积分14085
共 6 条评论
请问使用composer下载该插件需要**吗
用composer是要翻的
我不是用composer安装的 我下载了一个DatePicker 放在widgets文件下 用不了 帮我看看是哪方面的原因?
可以设置时分秒的格式吗,该如何设置
其实看源码之后我就知道怎么设置了,没必要像你哪样啊。
前提是必须安装这个插件: 具体看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' ] ]);?>
您的这个composer命令我执行不了
@乌蝇哥 使用 composer require "2amigos/yii2-date-picker-widget":"*"
环境变量配置好的情况下 php composer.phar = composer
怎么让插件只能选择年月,不要选择日
关于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中,怎么要怎么做呢?求解
你这个问题解决了吗 我也遇到了