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 fsockopen写的HTTP下载的类
Feb 22 PHP
一个自定义位数的php多用户计数器代码
Mar 11 PHP
php中理解print EOT分界符和echo EOT的用法区别小结
Feb 21 PHP
php 读取shell管道传输过来的内容
Mar 01 PHP
php中http_build_query 的一个问题
Mar 25 PHP
PHP中防止直接访问或查看或下载config.php文件的方法
Jul 07 PHP
PHP输入流php://input介绍
Sep 18 PHP
php存储过程调用实例代码
Feb 03 PHP
php将gd生成的图片缓存到memcache的小例子
Jun 05 PHP
php使用json_decode后数字对象转换成了科学计数法的解决方法
Feb 20 PHP
PHP实现的基于单向链表解决约瑟夫环问题示例
Sep 30 PHP
PHP _construct()函数讲解
Feb 03 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
ftp类(myftp.php)
2006/10/09 PHP
使用PHP socke 向指定页面提交数据
2008/07/23 PHP
jQuery UI Dialog控件中的表单无法正常提交的解决方法
2010/12/19 Javascript
html文件中jquery与velocity变量中的$冲突的解决方法
2013/11/01 Javascript
javascript类型转换示例
2014/04/29 Javascript
js带前后翻页的图片切换效果代码分享
2015/09/08 Javascript
JS简单限制textarea内输入字符数量的方法
2015/10/14 Javascript
创建一个类Person的简单实例
2016/05/17 Javascript
javascript加载xml 并解析各节点的值(实现方法)
2016/10/12 Javascript
微信小程序 蓝牙的实现实例代码
2017/06/27 Javascript
JS使用tween.js动画库实现轮播图并且有切换功能
2018/07/17 Javascript
微信小程序常用赋值方法小结
2019/04/30 Javascript
JS求1到任意数之间的所有质数的方法详解
2019/05/20 Javascript
vue项目中mock.js的使用及基本用法
2019/05/22 Javascript
JS使用Chrome浏览器实现调试线上代码
2020/07/23 Javascript
[01:05:29]DOTA2-DPC中国联赛 正赛 PSG.LGD vs Aster BO3 第二场 1月24日
2021/03/11 DOTA
python继承和抽象类的实现方法
2015/01/14 Python
Python中非常实用的一些功能和函数分享
2015/02/14 Python
Python使用PIL库实现验证码图片的方法
2016/03/11 Python
python爬虫_实现校园网自动重连脚本的教程
2018/04/22 Python
PyQt5实现拖放功能
2018/04/25 Python
Python使用uuid库生成唯一标识ID
2020/02/12 Python
推荐10个HTML5响应式框架
2016/02/25 HTML / CSS
手工制作的豪华英式沙发和沙发床:Willow & Hall
2019/05/03 全球购物
一家专门经营包包的英国网站:MyBag
2019/09/08 全球购物
PHP如何对用户密码进行加密
2014/07/31 面试题
JavaScript实现页面动态验证码的实现示例
2021/03/23 Javascript
物流管理毕业生自荐信
2013/10/24 职场文书
《中国梦我的梦》中学生演讲稿
2014/08/20 职场文书
纪念9.18事变演讲稿
2014/09/14 职场文书
电影建国大业观后感
2015/06/01 职场文书
英语读书笔记
2015/07/02 职场文书
新员工入职感言范文!
2019/07/04 职场文书
导游词之开封禹王台风景区
2019/12/02 职场文书
Python制作动态字符画的源码
2021/08/04 Python
MySQL中order by的执行过程
2022/06/05 MySQL