PHP   发布时间:2019-11-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了yii2超好用的日期组件和时间组件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

<p style="box-sizing: border-box; text-align: left; padding-bottom: 0px; widows: 1; text-transform: none; BACkground-color: rgb(255,255,255); text-indent: 0px; margin: 0px 0px 8px; padding-left: 0px; letter-spacing: 0px; padding-right: 0px; font: 14px/20px 'Helvetica Neue',Helvetica,Arial,'Hiragino Sans GB','Hiragino Sans GB W3','WenQuanYi Micro Hei','Microsoft YaHei UI','Microsoft YaHei',sans-serif; word-wrap: break-word; white-space: normal; color: rgb(51,51,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">日期组件,时间组件在平时开发中是必不可少的。今天我们就来谈谈在yii2中的超好用的时间组件,也省的大家各种找js插件了。


<p style="box-sizing: border-box; text-align: left; padding-bottom: 0px; widows: 1; text-transform: none; BACkground-color: rgb(255,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">分享之前我们先预览下效果,看看到底怎么个好用法。

当然啦,好用不好用在于自我的感觉,光看上面的图片是感受不到的。再告诉你个好消息,这两款插件已经跟yii2整合了,使用起来也是灰常的简单哦。

关于日期组件跟时间组件,前者是date('Y-m-d')类型,后者是date('Y-m-d H:i:s')类型,自然不用多说。

我们先来看看时间组件扩展

既然是扩展组建,第一步当然是安装。

<code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,'monospace !important'; color: red; padding-top: 0px">composer require kartik-v/yii2-widget-datetiR_682_11845@epicker "*"


<p style="box-sizing: border-box; text-align: left; padding-bottom: 0px; widows: 1; text-transform: none; BACkground-color: rgb(255,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">

安装好之后,如果你的表单使用ActiveForm生成的,可以参下面的代码


<div class="jb51code">
<pre class="brush:php;">
use kartik\datetiR_682_11845@e\datetiR_682_11845@ePicker;
<?= $form->field($model,'created_at')->widget(datetiR_682_11845@ePicker::classname(),[
'options' => ['placeholder' => ''],'pluginOptions' => [
'autoclose' => true,'todayHighlight' => true,]
]); ?>

BACkground-color: rgb(255,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">

有些不喜欢用ActiveForm生成表单的同学就需要参下面的用法了

php;"> use kartik\datetiR_682_11845@e\datetiR_682_11845@ePicker; echo ''; echo datetiR_682_11845@ePicker::widget([ 'name' => 'Article[created_at]','options' => ['placeholder' => ''],//注意,该方法更新的时候你需要指定value值 'value' => '2016-05-03 22:10:10','pluginOptions' => [ 'autoclose' => true,'format' => 'yyyy-mm-dd HH:ii:ss','todayHighlight' => true ] ]);

BACkground-color: rgb(255,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">至于哪个方便,@R_38_9772@。

BACkground-color: rgb(255,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">整个安装过程确实很简单,我们接下来以同样的方式进行安装日期组件。

BACkground: rgb(246,246,246); color: rgb(51,51); border-top: rgb(221,221) 1px solid; border-right: rgb(221,221) 1px solid; word-spacing: 0px; padding-top: 5px; -webkit-text-stroke-width: 0px">
composerrequirekartik-v/yii2-widget-datepicker"@dev"

BACkground-color: rgb(255,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">

安装好了后我们开始使用日期组件

php;"> use kartik\date\DatePicker; 'Article[created_at]','options' => ['placeholder' => '...'],//value值更新的时候需要加上 'value' => '2016-05-03','format' => 'yyyy-mm-dd',51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">

看了上面的代码,想必有同学已经猜到针对ActiveForm生成的日期组件的用法了。没错,就那么用,si不si很简单。

php;"> field($model,'created_at')->widget(DatePicker::classname(),51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">当然,上面的时间格式都是可以调整的,但是,日期组件,既然是日期,肯定也就只支持ymd三种类型的参数,不然跟时间组件又有啥差别。

'zh-CN',即可。

BACkground-color: rgb(255,51); word-break: break-all; word-spacing: 0px; padding-top: 0px; -webkit-text-stroke-width: 0px">最后,我们看看最终的效果图。

大佬总结

以上是大佬教程为你收集整理的yii2超好用的日期组件和时间组件全部内容,希望文章能够帮你解决yii2超好用的日期组件和时间组件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:yii2