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&&mysql)二
Oct 09 PHP
PHP+MYSQL开发工具及资源收藏
Jan 02 PHP
php数据库连接时容易出错的特殊符号问题
Sep 01 PHP
php读取文件内容至字符串中,同时去除换行、空行、行首行尾空格(Zjmainstay原创)
Jul 31 PHP
smarty模板局部缓存方法使用示例
Jun 17 PHP
自己写的php中文截取函数mb_strlen和mb_substr
Feb 09 PHP
Windows7下的php环境配置教程
Feb 28 PHP
php中将一个对象保存到Session中的方法
Mar 13 PHP
详解PHP序列化反序列化的方法
Oct 27 PHP
php加密之discuz内容经典加密方式实例详解
Feb 04 PHP
PHP策略模式定义与用法示例
Jul 27 PHP
详解php用static方法的原因
Sep 12 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
关于尾递归的使用详解
2013/05/02 PHP
PHPCMS V9 添加二级导航的思路详解
2016/10/20 PHP
php+Ajax无刷新验证用户名操作实例详解
2019/03/04 PHP
php精度计算的问题解析
2019/06/21 PHP
JavaScript内核之基本概念
2011/10/21 Javascript
js添加table的行和列 具体实现方法
2013/07/22 Javascript
jquery如何判断某元素是否具备指定的样式
2013/11/05 Javascript
初始Nodejs
2014/11/08 NodeJs
jQuery 中$(this).index与$.each的使用指南
2014/11/20 Javascript
jQuery向后台传入json格式数据的方法
2015/02/13 Javascript
JS建造者模式基本用法实例分析
2015/06/30 Javascript
js实现TAB切换对应不同颜色的代码
2015/08/31 Javascript
jQuery实现商品活动倒计时
2015/10/16 Javascript
webpack+vue.js快速入门教程
2016/10/12 Javascript
Javascript中this绑定的3种方法与比较
2016/10/13 Javascript
微信js-sdk分享功能接口常用逻辑封装示例
2016/10/13 Javascript
JS实现PC手机端和嵌入式滑动拼图验证码三种效果
2017/02/15 Javascript
微信小程序 图片加载(本地,网路)实例详解
2017/03/10 Javascript
Node实战之不同环境下配置文件使用教程
2018/01/02 Javascript
微信小程序实现人脸检测功能
2018/05/25 Javascript
基于vue中对鼠标划过事件的处理方式详解
2018/08/22 Javascript
开发一个Parcel-vue脚手架工具(详细步骤)
2018/09/22 Javascript
微信小程序监听用户登录事件的实现方法
2019/11/11 Javascript
Node.js Domain 模块实例详解
2020/03/18 Javascript
JavaScript实现多文件下载方法解析
2020/08/07 Javascript
让python在hadoop上跑起来
2016/01/27 Python
Python 实现数据库更新脚本的生成方法
2017/07/09 Python
python+selenium识别验证码并登录的示例代码
2017/12/21 Python
小白入门篇使用Python搭建点击率预估模型
2018/10/12 Python
不到20行代码用Python做一个智能聊天机器人
2019/04/19 Python
用python wxpy管理微信公众号并利用微信获取自己的开源数据
2019/07/30 Python
使用TensorFlow-Slim进行图像分类的实现
2019/12/31 Python
CSS3实现任意图片lowpoly动画效果实例
2017/05/11 HTML / CSS
承诺书怎么写
2014/03/26 职场文书
APP界面设计技巧和注意事项
2022/04/29 杂记
Python TypeError: ‘float‘ object is not subscriptable错误解决
2022/12/24 Python