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 相关文章推荐
xml+php动态载入与分页
Oct 09 PHP
PHP5中使用PDO连接数据库的方法
Aug 01 PHP
PHP性能优化准备篇图解PEAR安装
Dec 05 PHP
探讨PHP删除文件夹的三种方法
Jun 09 PHP
Codeigniter中mkdir创建目录遇到权限问题和解决方法
Jul 25 PHP
php中__destruct与register_shutdown_function执行的先后顺序问题
Oct 17 PHP
php取得字符串首字母的方法
Mar 25 PHP
PHP文件及文件夹操作之创建、删除、移动、复制
Jul 13 PHP
PHP中类的自动加载的方法
Mar 17 PHP
自制PHP框架之模型与数据库
May 07 PHP
CMSPRESS 10行代码搞定 PHP无限级分类2
Mar 30 PHP
详解PHP版本兼容之openssl调用参数
Jul 25 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实现二分查找算法代码分享
2011/06/24 PHP
php命令行使用方法和命令行参数说明
2014/04/08 PHP
php+MySQL判断update语句是否执行成功的方法
2014/08/28 PHP
PHP获取路径和目录的方法总结【必看篇】
2017/03/04 PHP
PHP whois查询类定义与用法示例
2019/04/03 PHP
PHP全局使用Laravel辅助函数dd
2019/12/26 PHP
JS实现简单的Canvas画图实例
2013/07/04 Javascript
谈谈encodeURI和encodeURIComponent以及escape的区别与应用
2015/11/24 Javascript
使用Jasmine和Karma对AngularJS页面程序进行测试
2016/03/05 Javascript
JS跨域交互(jQuery+php)之jsonp使用心得
2016/07/01 Javascript
微信小程序实现image组件图片自适应宽度比例显示的方法
2018/01/16 Javascript
Vue前端判断数据对象是否为空的实例
2020/09/02 Javascript
JavaScript Html实现移动端红包雨功能页面
2021/01/10 Javascript
Python基于贪心算法解决背包问题示例
2017/11/27 Python
python实现朴素贝叶斯分类器
2018/03/28 Python
深入浅析Python中list的复制及深拷贝与浅拷贝
2018/09/03 Python
pandas计算最大连续间隔的方法
2019/07/04 Python
python 比较2张图片的相似度的方法示例
2019/12/18 Python
pytorch 使用加载训练好的模型做inference
2020/02/20 Python
降低python版本的操作方法
2020/09/11 Python
Python+OpenCV检测灯光亮点的实现方法
2020/11/02 Python
PyTorch中clone()、detach()及相关扩展详解
2020/12/09 Python
Python Pygame实现俄罗斯方块
2021/02/19 Python
玩具反斗城美国官网:Toys"R"Us
2016/09/17 全球购物
伦敦时尚生活的缩影:LN-CC
2017/01/24 全球购物
南非最大的花卉和送礼服务:NetFlorist
2017/09/13 全球购物
财务会计专业推荐信
2013/11/30 职场文书
高三政治教学反思
2014/02/06 职场文书
《威尼斯的小艇》教学反思
2014/02/17 职场文书
土木工程专业推荐信
2014/02/19 职场文书
民间个人借款协议书
2014/09/30 职场文书
导游词之香港-太平山顶
2019/10/18 职场文书
vue-cli4.5.x快速搭建项目
2021/05/30 Vue.js
Java8中Stream的一些神操作
2021/11/02 Java/Android
springboot实现string转json json里面带数组
2022/06/16 Java/Android
MySQL中LAG()函数和LEAD()函数的使用
2022/08/14 MySQL