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 相关文章推荐
JAVA/JSP学习系列之六
Oct 09 PHP
一个简洁的多级别论坛
Oct 09 PHP
php数据库连接时容易出错的特殊符号问题
Sep 01 PHP
使用php将某个目录下面的所有文件罗列出来的方法详解
Jun 21 PHP
Php中使用Select 查询语句的实例
Feb 19 PHP
php获取从百度、谷歌等搜索引擎进入网站关键词的方法
Jul 08 PHP
php结合md5的加密解密算法实例
Sep 30 PHP
PHP实现加密文本文件并限制特定页面的存取的效果
Oct 21 PHP
CI框架中类的自动加载问题分析
Nov 21 PHP
解决微信授权回调页面域名只能设置一个的问题
Dec 11 PHP
PHP在弹框中获取foreach中遍历的id值并传递给地址栏
Jun 13 PHP
php操作redis命令及代码实例大全
Nov 19 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使之能同时支持GIF和JPEG
2006/10/09 PHP
php和数据库结合的一个简单的web实例 代码分析 (php初学者)
2011/07/28 PHP
深入mysql_fetch_row()与mysql_fetch_array()的区别详解
2013/06/05 PHP
php简单防盗链实现方法
2015/07/29 PHP
js的event详解。
2006/09/06 Javascript
jQuery写fadeTo示例代码
2014/02/21 Javascript
将form表单中的元素转换成对象的方法适用表单提交
2014/05/02 Javascript
javascript闭包(Closure)用法实例简析
2015/11/30 Javascript
jQuery实现放大镜效果实例代码
2016/03/17 Javascript
js实现(全选)多选按钮的方法【附实例】
2016/03/30 Javascript
微信公众号-获取用户信息(网页授权获取)实现步骤
2016/10/21 Javascript
javascript实现无法关闭的弹框
2016/11/27 Javascript
jQuery实现CheckBox全选、全不选功能
2017/01/11 Javascript
JQuery.dataTables表格插件添加跳转到指定页
2017/06/09 jQuery
利用JavaScript将Excel转换为JSON示例代码
2019/06/14 Javascript
Vue父组件如何获取子组件中的变量
2019/07/24 Javascript
vue父子组件通信的高级用法示例
2019/08/29 Javascript
Vue打包后访问静态资源路径问题
2019/11/08 Javascript
Vue的双向数据绑定实现原理解析
2020/02/17 Javascript
es6函数之尾递归用法实例分析
2020/04/25 Javascript
Python实现设置windows桌面壁纸代码分享
2015/03/28 Python
Python实现读取SQLServer数据并插入到MongoDB数据库的方法示例
2018/06/09 Python
Python用61行代码实现图片像素化的示例代码
2018/12/10 Python
python print输出延时,让其立刻输出的方法
2019/01/07 Python
python对象转字典的两种实现方式示例
2019/11/07 Python
Tensorflow实现多GPU并行方式
2020/02/03 Python
给 TensorFlow 变量进行赋值的方式
2020/02/10 Python
Python面向对象程序设计之私有变量,私有方法原理与用法分析
2020/03/23 Python
详解Pandas 处理缺失值指令大全
2020/07/30 Python
利用CSS3实现开门效果实例源码
2016/08/22 HTML / CSS
Zooplus葡萄牙:欧洲领先的网上宠物商店
2018/07/01 全球购物
美国网上书店:Barnes & Noble
2018/08/15 全球购物
校园十大歌手策划书
2014/02/01 职场文书
幼儿园教师读书笔记
2015/06/29 职场文书
保险公司2016开门红口号集锦
2015/12/24 职场文书
Redis特殊数据类型Geospatial地理空间
2022/06/01 Redis