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 相关文章推荐
文章推荐系统(三)
Oct 09 PHP
php下使用无限生命期Session的方法
Mar 16 PHP
使用Limit参数优化MySQL查询的方法
Nov 12 PHP
php array_search() 函数使用
Apr 13 PHP
PHP重定向的3种方式
Mar 07 PHP
php树型类实例
Dec 05 PHP
大家在抢红包,程序员在研究红包算法
Aug 31 PHP
PHP指定截取字符串中的中英文或数字字符的实例分享
Mar 18 PHP
ThinkPHP Where 条件中常用表达式示例(详解)
Mar 31 PHP
php往mysql中批量插入数据实例教程
Dec 12 PHP
thinkphp5框架实现的自定义扩展类操作示例
May 16 PHP
Swoole源码中如何查询Websocket的连接问题详解
Aug 30 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微信公众号支付接口
2016/08/04 PHP
MSN消息提示类
2006/09/05 Javascript
有一段有意思的代码-javascript现实多行信息
2007/08/26 Javascript
ASP中进行HTML数据及JS数据编码函数
2009/11/11 Javascript
仅IE9/10同时支持script元素的onload和onreadystatechange事件分析
2011/04/27 Javascript
jQuery+.net实现浏览更多内容(改编php版本)
2013/03/28 Javascript
JS Pro-深入面向对象的程序设计之继承的详解
2013/05/07 Javascript
js将控件隐藏的方法及display属性介绍
2013/07/04 Javascript
点击按钮或链接不跳转只刷新页面的脚本整理
2013/10/22 Javascript
使用js实现关闭js弹出层的窗口
2014/02/10 Javascript
js判断undefined类型示例代码
2014/02/10 Javascript
jQuery控制网页打印指定区域的方法
2015/04/07 Javascript
jQuery读取XML文件的方法示例
2017/02/03 Javascript
bootstrap treeview 树形菜单带复选框及级联选择功能
2018/06/08 Javascript
zepto.js 实时监听输入框的方法
2018/12/04 Javascript
nodejs搭建本地服务器并访问文件操作示例
2019/05/11 NodeJs
Vue 2.0 侦听器 watch属性代码详解
2019/06/19 Javascript
跟老齐学Python之关于类的初步认识
2014/10/11 Python
Python中使用摄像头实现简单的延时摄影技术
2015/03/27 Python
python使用wmi模块获取windows下硬盘信息的方法
2015/05/15 Python
Python 模块EasyGui详细介绍
2017/02/19 Python
python算法表示概念扫盲教程
2017/04/13 Python
Python中property属性实例解析
2018/02/10 Python
python 集合 并集、交集 Series list set 转换的实例
2018/05/29 Python
python 实现对文件夹中的图像连续重命名方法
2018/10/25 Python
PyQt5 QTableView设置某一列不可编辑的方法
2019/06/25 Python
Python Tkinter模块 GUI 可视化实例
2019/11/20 Python
python中property和setter装饰器用法
2019/12/19 Python
韩国江南富人区高端时尚百货商场:Galleria(格乐丽雅)
2018/03/27 全球购物
.net C#面试题
2012/08/28 面试题
优秀应届毕业生自荐信
2013/11/16 职场文书
快递员岗位职责
2014/09/12 职场文书
个人学习党的群众路线教育实践活动心得体会
2014/11/05 职场文书
黄石寨导游词
2015/02/05 职场文书
redis实现排行榜功能
2021/05/24 Redis
Django实现drf搜索过滤和排序过滤
2021/06/21 Python