Yii2 Format 如何使用
$formatter = \Yii::$app->formatter;
// output: January 1, 2014
echo $formatter->asDate('2014-01-01', 'long');
// output: 12.50%
echo $formatter->asPercent(0.125, 2); // output: <a href="mailto:cebe@example.com">cebe@example.com</a>
echo $formatter->asEmail('cebe@example.com'); // output: Yes
echo $formatter->asBoolean(true); // it also handles display of null values: // output: (Not set
echo $formatter->asDate(null);
// output: January 1, 2014
echo Yii::$app->formatter->format('2014-01-01', 'date'); // you can also use an array to specify parameters for the format method: // `2` is the value for the $decimals parameter of the asPercent()-method. // output: 12.50%
echo Yii::$app->formatter->format(0.125, ['percent', 2]);
echo Yii::$app->formatter->asTime(1412599260);
// 14:41:00 // formatting a datetime string (in UTC) as a time
echo Yii::$app->formatter->asTime('2014-10-06 12:41:00'); // 14:41:00 // formatting a datetime string (in CEST) as a time
echo Yii::$app->formatter->asTime('2014-10-06 14:41:00 CEST'); // 14:41:00
Yii::$app->formatter->locale = 'en-US';
echo Yii::$app->formatter->asDate('2014-01-01'); // output: January 1, 2014
Yii2 Format 如何使用的更多相关文章
- Yii2中的format
关于format,这个也非常方便, 用来格式化内容的. 如下代码: <?= DetailView::widget([ 'model' => $model, 'attributes' =&g ...
- Yii2 使用json 和设置component 中'format' => yii\web\Response::FORMAT_JSON 的区别
在Yii2中如果设置了 'response' => [ 'format' => yii\web\Response::FORMAT_JSON, 'charset' => 'UTF- ...
- Yii2 时间控件之把layDate做成widget
实现效果如下 1.把layDate封装成Yii2的widget,存在 "\common\widgets"目录下,命名为DycLayDate,具体引用查看代码. 2.对应的model ...
- Yii2 用户登录
在Yii2的basic版本中默认是从一个数组验证用户名和密码,如何改为从数据表中查询验证呢?且数据库的密码要为哈希加密密码验证? 下面我们就一步一步解析Yii2的登录过程. 一. 创建user表模型 ...
- Yii2中的零碎知识点
PHP最佳实践 1 PHP获取时间戳:echo time(); 时间戳转换 date('Y-m-d H:i:s', $时间戳); 2 linux 显示命令 ls 显示所有文件夹 查看命令:tail ...
- yii2超好用的日期组件和时间组件
作者:白狼 出处:http://www.manks.top/yii2_datetimepicker.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 ...
- yii2 输出xml格式数据
作者:白狼 出处:http://www.manks.top/yii2_xml_response.html.html本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文 ...
- yii2 GridView常见操作
作者:白狼 出处:http://www.manks.top/article/yii2_gridview 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则 ...
- [PHP]Yii2框架的坑
[PHP]Yii2框架的坑.md-/Users/zjh/Documents/我的文章/[PHP]Yii2框架的坑 html{font-family: sans-serif;-ms-text-size- ...
随机推荐
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
- [Android Pro] RecyclerView实现瀑布流效果(二)
referece to : http://blog.csdn.net/u010687392 在上篇中我们知道RecyclerView中默认给我们提供了三种布局管理器,分别是LinearLayoutMa ...
- Nginx与Redis解决高并发问题
原文链接:http://bbs.phpchina.com/forum.php?mod=viewthread&tid=229629 第一版产品采用的是Jquery,Nginx,PHP(CI框架) ...
- linux shell的切换
查看系统可用shell种类:(一般是bash shell) ➜ ~ chsh -l /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/zsh 修改当前的sh ...
- Android 利用日志消息调试程序
Log类提供了下面几个静态方法 , Log.e(): 错误: Log.w(): 警告: Log.i(): 信息: Log.d(); 调试: Log.v(); 详细:
- Android横屏竖屏切换的问题
Android横屏竖屏切换的问题 http://blog.sina.com.cn/s/blog_77c632410101790w.html
- mysql一次插入多条数据
mysql一次插入多条数据: INSERT INTO hk_test(username, passwd) VALUES ('qmf2', 'qmf2'),('qmf3', 'qmf3'),('qmf4 ...
- WireShark抓包过程
wireshark是非常流行的网络封包分析软件,功能十分强大.可以截取各种网络封包,显示网络封包的详细信息.使用wireshark的人必须了解网络协议,否则就看不懂wireshark了. 为了安全考虑 ...
- HTTP基础03--HTTP报文
报文大致结构: 报文首部: 请求行(请求报文)/状态行(响应报文) 首部字段:请求和响应的各种条件和属性的各类首部: 其它(Cookie) 空行 报文主体(不是必须) 编码提升传输速率: 报文主体和实 ...
- Xamarin Android开发实战(上册)大学霸内部资料
Xamarin Android开发实战(上册)大学霸内部资料 试读文档下载地址:http://pan.baidu.com/s/1jGEHhhO 密码:vcfm 介绍: 本教程是国内唯一的Xamar ...