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 相关文章推荐
默默简单的写了一个模板引擎
Jan 02 PHP
PHP,ASP.JAVA,JAVA代码格式化工具整理
Jun 15 PHP
解析smarty模板中类似for的功能实现
Jun 18 PHP
用PHP解决的一个栈的面试题
Jul 02 PHP
PHP中的reflection反射机制测试例子
Aug 05 PHP
php禁止某ip或ip地址段访问的方法
Feb 25 PHP
php转换颜色为其反色的方法
Apr 27 PHP
PHP使用redis实现统计缓存mysql压力的方法
Nov 14 PHP
PHP简单实现欧拉函数Euler功能示例
Nov 06 PHP
PHP实现的字符串匹配算法示例【sunday算法】
Dec 19 PHP
php处理抢购类功能的高并发请求
Feb 08 PHP
TP5框架实现上传多张图片的方法分析
Mar 29 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
ThinkPHP模板范围判断输出In标签与Range标签用法详解
2014/06/30 PHP
php自定文件保存session的方法
2014/12/10 PHP
php实现encode64编码类实例
2015/03/24 PHP
浅谈使用PHP开发微信支付的流程
2015/10/04 PHP
简述php环境搭建与配置
2016/12/05 PHP
PHP+mysql实现的三级联动菜单功能示例
2019/02/15 PHP
php异常处理捕获错误整理
2019/09/23 PHP
弹出广告特效(一个IP只弹出一次)的代码
2007/07/27 Javascript
基于jQuery图片平滑连续滚动插件
2009/04/27 Javascript
基于jquery插件制作左右按钮与标题文字图片切换效果
2013/11/07 Javascript
js实现select下拉框菜单
2015/12/08 Javascript
jQuery实现表单动态添加数据并提交的方法
2018/07/19 jQuery
Element中的Cascader(级联列表)动态加载省\市\区数据的方法
2019/03/27 Javascript
[01:36:57]【09DOTA2第一视角】小骷髅
2014/04/16 DOTA
[26:52]LGD vs EG 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/18 DOTA
简洁的十分钟Python入门教程
2015/04/03 Python
python中的编码知识整理汇总
2016/01/26 Python
python 定时任务去检测服务器端口是否通的实例
2019/01/26 Python
python远程连接MySQL数据库
2019/04/19 Python
python Django里CSRF 对应策略详解
2019/08/05 Python
python 画3维轨迹图并进行比较的实例
2019/12/06 Python
python实现扑克牌交互式界面发牌程序
2020/04/22 Python
Python基于wordcloud及jieba实现中国地图词云图
2020/06/09 Python
浅析python连接数据库的重要事项
2021/02/22 Python
欧洲著名的珠宝和手表网上商城:uhrcenter
2017/04/10 全球购物
卡西欧B级产品官方网站:Casio Outlet
2018/05/22 全球购物
职业教育毕业生求职信
2013/11/09 职场文书
网页设计个人找工作求职信
2013/11/28 职场文书
公司财务总监岗位职责
2013/12/14 职场文书
自动化专业个人求职信范文
2013/12/30 职场文书
大学生家政服务项目创业计划书
2014/01/30 职场文书
人力资源总监工作说明
2014/03/03 职场文书
就业推荐表自我鉴定范文
2014/03/21 职场文书
财政局个人年终总结
2015/03/03 职场文书
廉洁自律承诺书范文
2015/04/28 职场文书
浅谈如何提高PHP代码质量之单元测试
2021/05/28 PHP