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 相关文章推荐
PHP环境搭建最新方法
Sep 05 PHP
将数组写入txt文件 var_export
Apr 21 PHP
php array_unique之后json_encode需要注意
Jan 02 PHP
PHP删除HTMl标签的三种解决方法
Jun 30 PHP
Php中使用Select 查询语句的实例
Feb 19 PHP
ThinkPHP空模块和空操作详解
Jun 30 PHP
PHP5.3安装Zend Guard Loader图文教程
Sep 29 PHP
PHP中使用Imagick读取pdf并生成png缩略图实例
Jan 21 PHP
PHP格式化MYSQL返回float类型的方法
Mar 30 PHP
PHP实现导出excel数据的类库用法示例
Oct 15 PHP
PHP之将POST数据转化为字符串的实现代码
Nov 03 PHP
PHP实现的自定义图像居中裁剪函数示例【测试可用】
Aug 11 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实现手机号码中间四位用星号(*)隐藏的自定义函数分享
2014/09/27 PHP
PHP Hash算法:Times33算法代码实例
2015/05/13 PHP
Laravel5.7 数据库操作迁移的实现方法
2019/04/12 PHP
IE6不能修改NAME问题的解决方法
2010/09/03 Javascript
extjs之去除s.gif的影响
2010/12/25 Javascript
jquery 日期控件datepicker属性详细解析
2013/11/08 Javascript
getAsDataURL在Firefox7.0下无法预览本地图片的解决方法
2013/11/15 Javascript
javascript转换日期字符串为Date日期对象的方法
2015/02/13 Javascript
关于session和cookie的简单理解
2016/06/08 Javascript
微信小程序 MINA文件结构
2016/10/17 Javascript
使用jsonp实现跨域获取数据实例讲解
2016/12/25 Javascript
vue props default Array或是Object的正确写法说明
2020/07/30 Javascript
Vue登录拦截 登录后继续跳转指定页面的操作
2020/08/04 Javascript
[19:15]DK战队纪录片
2014/09/02 DOTA
举例讲解Python中的Null模式与桥接模式编程
2016/02/02 Python
浅析python实现scrapy定时执行爬虫
2018/03/04 Python
浅谈Python traceback的优雅处理
2018/08/31 Python
tensorflow实现逻辑回归模型
2018/09/08 Python
Python使用Tkinter实现滚动抽奖器效果
2020/01/06 Python
python3使用Pillow、tesseract-ocr与pytesseract模块的图片识别的方法
2020/02/26 Python
python3中sorted函数里cmp参数改变详解
2020/03/12 Python
Python如何实现远程方法调用
2020/08/07 Python
Farfetch澳大利亚官网:Farfetch Australia
2020/04/26 全球购物
Unineed中文官网:高端护肤美妆与时尚配饰,英国直邮
2020/07/23 全球购物
公司庆典邀请函范文
2014/01/13 职场文书
先进事迹报告会感言
2014/01/24 职场文书
会议邀请书范文
2014/02/02 职场文书
跟单业务员岗位职责
2014/03/08 职场文书
大学生感恩父母演讲稿
2014/08/28 职场文书
加强机关作风建设心得体会
2014/10/22 职场文书
全国法院系统开展党的群众路线教育实践活动综述(全文)
2014/10/25 职场文书
五好文明家庭事迹材料
2014/12/20 职场文书
出纳岗位职责
2015/01/31 职场文书
用电申请报告范文
2015/05/18 职场文书
杨善洲电影观后感
2015/06/04 职场文书
公司保密管理制度
2015/08/04 职场文书