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 相关文章推荐
一个odbc连mssql分页的类
Oct 09 PHP
php sprintf()函数让你的sql操作更安全
Jul 23 PHP
CI框架中libraries,helpers,hooks文件夹详细说明
Jun 10 PHP
php使用date和strtotime函数输出指定日期的方法
Nov 14 PHP
Yii不依赖Model的表单生成器用法实例
Dec 04 PHP
php显示时间常用方法小结
Jun 05 PHP
PHP YII框架开发小技巧之模型(models)中rules自定义验证规则
Nov 16 PHP
Zend Framework框架路由机制代码分析
Mar 22 PHP
php生成图片验证码的方法
Apr 15 PHP
php5.x禁用eval的操作方法
Oct 19 PHP
PHP children()函数讲解
Feb 03 PHP
Laravel框架查询构造器简单示例
May 08 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&mysql(五)
2006/10/09 PHP
114啦源码(114la)不能生成地方房产和地方报刊问题4级页面0字节的解决方法
2012/01/12 PHP
php输出xml属性的方法
2015/03/19 PHP
php截取指定2个字符之间字符串的方法
2015/04/15 PHP
php微信高级接口群发 多客服
2016/06/23 PHP
CodeIgniter框架常见用法工作总结
2017/03/16 PHP
2种jQuery 实现刮刮卡效果
2015/02/01 Javascript
JavaScript数据类型详解
2015/04/01 Javascript
jquery获取当前元素索引值用法实例
2015/06/10 Javascript
javascript中的五种基本数据类型
2015/08/26 Javascript
jQuery autoComplete插件两种使用方式及动态改变参数值的方法详解
2016/10/24 Javascript
详解Javascript百度地图接口开发文档中的类和方法
2017/02/07 Javascript
解决vue 更改计算属性后select选中值不更改的问题
2018/03/02 Javascript
angular2/ionic2 实现搜索结果中的搜索关键字高亮的示例
2018/08/17 Javascript
WebGL学习教程之Three.js学习笔记(第一篇)
2019/04/25 Javascript
[02:08:58]2014 DOTA2国际邀请赛中国区预选赛 Ne VS CIS
2014/05/22 DOTA
python 参数列表中的self 显式不等于冗余
2008/12/01 Python
Python算法之栈(stack)的实现
2014/08/18 Python
零基础写python爬虫之抓取糗事百科代码分享
2014/11/06 Python
python字典多键值及重复键值的使用方法(详解)
2016/10/31 Python
python里使用正则表达式的组嵌套实例详解
2017/10/24 Python
Tensorflow中使用tfrecord方式读取数据的方法
2018/06/19 Python
Python爬虫框架scrapy实现downloader_middleware设置proxy代理功能示例
2018/08/04 Python
使用tqdm显示Python代码执行进度功能
2019/12/08 Python
python GUI库图形界面开发之PyQt5布局控件QHBoxLayout详细使用方法与实例
2020/03/06 Python
python语言实现贪吃蛇游戏
2020/11/13 Python
德国滑雪和户外用品网上商店:XSPO
2019/10/30 全球购物
N:Philanthropy官网:美国洛杉矶基础款服装
2020/06/09 全球购物
自我评价范文
2013/12/22 职场文书
打架检讨书500字
2014/01/29 职场文书
党员教师工作决心书
2014/03/13 职场文书
2014领导干部四风问题查摆思想汇报
2014/09/13 职场文书
2015教师年度工作总结范文
2015/04/07 职场文书
征求意见函
2015/06/05 职场文书
浅谈Python列表嵌套字典转化的问题
2021/04/07 Python
windows11选中自动复制怎么开启? Win11自动复制所选内容的方法
2022/07/23 数码科技