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中与数组相关的函数
Mar 22 PHP
php Undefined index和Undefined variable的解决方法
Mar 27 PHP
php随机输出名人名言的代码
Oct 07 PHP
PHP实现的简单日历类
Nov 29 PHP
php使用Jpgraph绘制柱形图的方法
Jun 10 PHP
PHP查找与搜索数组元素方法总结
Jun 12 PHP
php similar_text()函数的定义和用法
May 12 PHP
ThinkPHP5实现作业管理系统中处理学生未交作业与已交作业信息的方法
Nov 12 PHP
php中Redis的应用--消息传递
Mar 28 PHP
PHP使用SWOOLE扩展实现定时同步 MySQL 数据
Apr 09 PHP
PHP编译configure时常见错误的总结
Aug 17 PHP
PHP实现图的邻接矩阵表示及几种简单遍历算法分析
Nov 24 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中的(伪)多线程与多进程
2013/07/01 PHP
PHP 错误处理机制
2015/07/06 PHP
php根据命令行参数生成配置文件详解
2019/03/15 PHP
JQuery中的$.getJSON 使用说明
2011/03/10 Javascript
JS获取鼠标坐标的实例方法
2013/07/18 Javascript
javaScript如何处理从java后台返回的list
2014/04/24 Javascript
js中iframe调用父页面的方法
2014/10/30 Javascript
js面向对象实现canvas制作彩虹球喷枪效果
2016/09/24 Javascript
Angular和百度地图的结合实例代码
2016/10/19 Javascript
JS去除字符串中空格的方法
2017/02/14 Javascript
jQuery插件MovingBoxes实现左右滑动中间放大图片效果
2017/02/28 Javascript
js绑定事件和解绑事件
2017/04/27 Javascript
vue页面跳转后返回原页面初始位置方法
2018/02/11 Javascript
浅谈Angular HttpClient简单入门
2018/05/04 Javascript
详解在vue-cli项目下简单使用mockjs模拟数据
2018/10/19 Javascript
jQuery实现的别踩白块小游戏完整示例
2019/01/07 jQuery
微信小程序+腾讯地图开发实现路径规划绘制
2019/05/22 Javascript
javascript 对象 与 prototype 原型用法实例分析
2019/11/11 Javascript
微信小程序实现打卡签到页面
2020/09/21 Javascript
Python闭包装饰器使用方法汇总
2020/06/29 Python
pycharm专业版远程登录服务器的详细教程
2020/09/15 Python
python Scrapy框架原理解析
2021/01/04 Python
html+css实现自定义图片上传按钮功能
2019/09/04 HTML / CSS
使用phonegap播放音频的实现方法
2017/03/31 HTML / CSS
CK美国官网:Calvin Klein
2016/08/26 全球购物
艺术设计专业个人求职信
2013/09/21 职场文书
应届生高等护理求职信
2013/10/12 职场文书
数控专业个人求职信范例
2013/11/29 职场文书
策划创业计划书
2014/02/06 职场文书
学生会主席竞聘书
2014/03/31 职场文书
经典团队口号大全
2014/06/21 职场文书
大学生第一学年自我鉴定
2014/09/12 职场文书
建筑横幅标语
2014/10/09 职场文书
离婚协议书范文2014
2014/10/16 职场文书
团支部组织委员竞选稿
2015/11/21 职场文书
Python中第三方库Faker的使用详解
2022/04/02 Python