php Smarty date_format [格式化时间日期]


Posted in PHP onMarch 15, 2010

Example 5-8. date_format[日期格式]
index.php:

$smarty = new Smarty; 
$smarty->assign('yesterday', strtotime('-1 day')); 
$smarty->display('index.tpl'); 
index.tpl: 
{$smarty.now|date_format} 
{$smarty.now|date_format:"%A, %B %e, %Y"} 
{$smarty.now|date_format:"%H:%M:%S"} 
{$yesterday|date_format} 
{$yesterday|date_format:"%A, %B %e, %Y"} 
{$yesterday|date_format:"%H:%M:%S"}

OUTPUT:
Feb 6, 2001 
Tuesday, February 6, 2001 
:33:00 
Feb 5, 2001 
Monday, February 5, 2001 
:33:00

Example 5-9. date_format conversion specifiers[日期转换说明]
%a - abbreviated weekday name according to the current locale 
(根据当地格式输出“星期”缩写格式) 
%A - full weekday name according to the current locale 
(根据当地格式输出“星期”全称格式) 
%b - abbreviated month name according to the current locale 
(根据当地格式输出“月”缩写格式) 
%B - full month name according to the current locale 
(根据当地格式输出“月”全称格式) 
%c - preferred date and time representation for the current locale 
%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99) 
%d - day of the month as a decimal number (range 00 to 31) 
%D - same as %m/%d/%y 
%e - day of the month as a decimal number, a single digit is preceded by a 
space (range 1 to 31) 
%g - Week-based year within century [00,99] 
%G - Week-based year, including the century [0000,9999] 
%h - same as %b 
%H - hour as a decimal number using a 24-hour clock (range 00 to 23) 
%I - hour as a decimal number using a 12-hour clock (range 01 to 12) 
%j - day of the year as a decimal number (range 001 to 366) 
%k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23) 
%l - hour as a decimal number using a 12-hour clock, single digits preceeded by 
a space (range 1 to 12) 
%m - month as a decimal number (range 01 to 12) 
%M - minute as a decimal number 
%n - newline character 
%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale 
%r - time in a.m. and p.m. notation 
%R - time in 24 hour notation 
%S - second as a decimal number 
%t - tab character 
%T - current time, equal to %H:%M:%S 
%u - weekday as a decimal number [1,7], with 1 representing Monday 
%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week 
%V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 
is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. 
%w - day of the week as a decimal, Sunday being 0 
%W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week 
%x - preferred date representation for the current locale without the time 
%X - preferred time representation for the current locale without the date 
%y - year as a decimal number without a century (range 00 to 99) 
%Y - year as a decimal number including the century 
%Z - time zone or name or abbreviation 
%% - a literal `%' character

PROGRAMMERS NOTE: date_format is essentially a wrapper to PHP's strftime()
function. You may have more or less conversion specifiers available depending
on your system's strftime() function where PHP was compiled. Check your
system's manpage for a full list of valid specifiers.
程序员提示:date_format本质上是php的strftime()函数的一个包装。
当php被编译的时候你可以或多或少的依靠系统的strftime()转换有效的区分符。
可以查看系统手册的有效区分符的全表.
PHP 相关文章推荐
Apache2 httpd.conf 中文版
Dec 06 PHP
PHP获得用户使用的代理服务器ip即真实ip
Dec 31 PHP
PHP判断指定时间段的2个方法
Mar 14 PHP
ThinkPHP调试模式与日志记录概述
Aug 22 PHP
php中mt_rand()随机数函数用法
Nov 24 PHP
PHP各种异常和错误的拦截方法及发生致命错误时进行报警
Jan 19 PHP
PHP生成和获取XML格式数据的方法
Mar 04 PHP
PHP实现JS中escape与unescape的方法
Jul 11 PHP
php 实现一个字符串加密解密的函数实例代码
Nov 01 PHP
PHP中命名空间的使用例子
Mar 22 PHP
PHP+fiddler抓包采集微信文章阅读数点赞数的思路详解
Dec 20 PHP
Yii中特殊行为ActionFilter的使用方法示例
Oct 18 PHP
libmysql.dll与php.ini是否真的要拷贝到c:\windows目录下呢
Mar 15 #PHP
php下获取客户端ip地址的函数
Mar 15 #PHP
PHP 模拟$_PUT实现代码
Mar 15 #PHP
php Xdebug 调试扩展的安装与使用.
Mar 13 #PHP
php5 non-thread-safe和thread-safe这两个版本的区别分析
Mar 13 #PHP
php 无法载入mysql扩展
Mar 12 #PHP
PHP生成Flash动画的实现代码
Mar 12 #PHP
You might like
编写PHP脚本清除WordPress头部冗余代码的方法讲解
2016/03/01 PHP
PHP排序算法之简单选择排序(Simple Selection Sort)实例分析
2018/04/20 PHP
JS写的数字拼图小游戏代码[学习参考]
2008/10/29 Javascript
用jquery实现学校的校历(asp.net+jquery ui 1.72)
2010/01/01 Javascript
js自执行函数的几种不同写法的比较
2012/08/16 Javascript
jQuery弹出(alert)select选择的值
2013/04/21 Javascript
JavaScript 实现简单的倒计时弹窗DEMO附图
2014/03/05 Javascript
JavaScript各类型的关系图解
2015/10/16 Javascript
jquery mobile 实现自定义confirm确认框效果的简单实例
2016/06/17 Javascript
Ajax+FormData+javascript实现无刷新表单信息提交
2016/10/24 Javascript
关于JavaScript中事件绑定的方法总结
2016/10/26 Javascript
jquery Easyui Datagrid实现批量操作(编辑,删除,添加)
2017/02/20 Javascript
jquery实现弹窗功能(窗口居中显示)
2017/02/27 Javascript
详解React项目的服务端渲染改造(koa2+webpack3.11)
2018/03/19 Javascript
JS开发常用工具函数(小结)
2019/07/04 Javascript
python 性能优化方法小结
2017/03/31 Python
最近Python有点火? 给你7个学习它的理由!
2017/06/26 Python
numpy实现合并多维矩阵、list的扩展方法
2018/05/08 Python
python文件操作之批量修改文件后缀名的方法
2018/08/10 Python
Python连接Redis的基本配置方法
2018/09/13 Python
python openCV获取人脸部分并存储功能
2019/08/28 Python
PyCharm中Matplotlib绘图不能显示UI效果的问题解决
2020/03/12 Python
学习Python需要哪些工具
2020/09/04 Python
澳大利亚最好的厨具店:Kitchen Warehouse
2018/03/13 全球购物
西班牙最大的在线滑板和街头服饰商店:Fillow.net
2019/04/15 全球购物
地球鞋加拿大官网:Earth Shoes Canada
2020/11/17 全球购物
C#公司笔试题
2014/03/28 面试题
优秀团员个人的自我评价
2013/10/02 职场文书
大学本科毕业生求职简历的自我评价
2013/10/09 职场文书
医务人员竞聘职务自我评价分享
2013/11/08 职场文书
说明书范文
2014/05/07 职场文书
企业理念标语
2014/06/09 职场文书
超市理货员岗位职责
2014/07/04 职场文书
关于拾金不昧的感谢信
2015/01/21 职场文书
房地产销售员岗位职责
2015/04/11 职场文书
2016年小学推普宣传周活动总结
2016/04/06 职场文书