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+javascript液晶时钟
Oct 09 PHP
探讨php中header的用法详解
Jun 07 PHP
基于PHP+Ajax实现表单验证的详解
Jun 25 PHP
解析csv数据导入mysql的方法
Jul 01 PHP
php socket实现的聊天室代码分享
Aug 16 PHP
Yii实现多按钮保存与提交的方法
Dec 03 PHP
php使用CURL伪造IP和来源实例详解
Jan 15 PHP
浅谈PHP中output_buffering
Jul 13 PHP
php实现的二分查找算法示例
Jun 20 PHP
tp5(thinkPHP5)框架实现多数据库查询的方法
Jan 10 PHP
PHP将英文数字转换为阿拉伯数字实例讲解
Jan 28 PHP
PHP+jQuery实现即点即改功能示例
Feb 21 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
虹吸壶煮咖啡26个注意事项
2021/03/03 冲泡冲煮
PHP中的日期及时间
2006/11/23 PHP
利用PHP函数计算中英文字符串长度的方法
2014/11/11 PHP
php使用MySQL保存session会话的方法
2015/06/26 PHP
javascript奇异的arguments分析
2010/10/20 Javascript
JavaScript 基础篇之对象、数组使用介绍(三)
2012/04/07 Javascript
jQuery学习笔记之jQuery原型属性和方法
2014/06/09 Javascript
jQuery学习笔记之toArray()
2014/06/09 Javascript
javascript常用的方法分享
2015/07/01 Javascript
浅谈JS继承_寄生式继承 & 寄生组合式继承
2016/08/16 Javascript
Angular中ng-options下拉数据默认值的设定方法
2017/06/21 Javascript
nodejs body-parser 解析post数据实例
2017/07/26 NodeJs
Vue框架中正确引入JS库的方法介绍
2017/07/30 Javascript
微信小程序使用progress组件实现显示进度功能【附源码下载】
2017/12/12 Javascript
vue iview实现动态路由和权限验证功能
2018/04/17 Javascript
Webpack devServer中的 proxy 实现跨域的解决
2018/06/15 Javascript
vue中的mescroll搜索运用及各种填坑处理
2019/10/30 Javascript
antd的select下拉框因为数据量太大造成卡顿的解决方式
2020/10/31 Javascript
[51:36]EG vs VP 2018国际邀请赛淘汰赛BO3 第一场 8.24
2018/08/25 DOTA
[01:42]DOTA2 – 虚无之灵
2019/08/25 DOTA
python中sets模块的用法实例
2014/09/30 Python
python自然语言编码转换模块codecs介绍
2015/04/08 Python
python 对多个csv文件分别进行处理的方法
2019/01/07 Python
Python中模块(Module)和包(Package)的区别详解
2019/08/07 Python
Python使用scrapy爬取阳光热线问政平台过程解析
2019/08/14 Python
Django 项目布局方法(值得推荐)
2020/03/22 Python
python获取系统内存占用信息的实例方法
2020/07/17 Python
Intimissimi德国网上商店:意大利知名内衣品牌
2018/04/03 全球购物
车间主管岗位职责
2013/11/14 职场文书
电气工程及自动化专业自荐书范文
2013/12/18 职场文书
统计系教授推荐信
2014/02/28 职场文书
工程质量承诺书
2014/03/27 职场文书
民事诉讼代理授权委托书范本
2014/10/08 职场文书
结婚通知短信大全
2015/04/17 职场文书
学习杨善洲同志先进事迹心得体会
2016/01/23 职场文书
幼儿园教师辞职信
2019/06/21 职场文书