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 和 COM
Oct 09 PHP
php下将多个数组合并成一个数组的方法与实例代码
Feb 03 PHP
php中get_headers函数的作用及用法的详细介绍
Apr 27 PHP
php中的静态变量的基本用法
Mar 20 PHP
php判断两个浮点数是否相等的方法
Mar 14 PHP
PHP实现基于文本的摩斯电码生成器
Jan 11 PHP
给大家分享几个常用的PHP函数
Jan 15 PHP
php 截取中英文混合字符串的方法
May 31 PHP
PHP中“=>
Mar 01 PHP
Laravel jwt 多表(多用户端)验证隔离的实现
Dec 18 PHP
PHP日期和时间函数的使用示例详解
Aug 06 PHP
php引用传递
Apr 01 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编程与应用
2006/10/09 PHP
php对gzip文件或者字符串解压实例参考
2008/07/25 PHP
PHP原理之异常机制深入分析
2010/08/08 PHP
PHP冒泡算法详解(递归实现)
2014/11/10 PHP
php类的自动加载操作实例详解
2016/09/28 PHP
PHP缩略图生成和图片水印制作
2017/01/07 PHP
php实现和c#一致的DES加密解密实例
2017/07/24 PHP
利用php获得flv视频长度的实例代码
2017/10/26 PHP
PHP工厂模式的日常使用
2019/03/20 PHP
PHP发送邮件确认验证注册功能示例【修改别人邮件类】
2019/11/09 PHP
Centos7安装swoole扩展操作示例
2020/03/26 PHP
JavaScript Array Flatten 与递归使用介绍
2011/10/30 Javascript
javascript实现复制与粘贴操作实例
2014/10/16 Javascript
javascript中CheckBox全选终极方案
2015/05/20 Javascript
Javascript中的getUTCHours()方法使用详解
2015/06/10 Javascript
JS实现浏览器状态栏文字从右向左弹出效果代码
2015/10/27 Javascript
Bootstrap CSS布局之代码
2016/12/17 Javascript
关于Stream和Buffer的相互转换详解
2017/07/26 Javascript
vue3.0 CLI - 2.5 - 了解组件的三维
2018/09/14 Javascript
js+html实现点名系统功能
2019/11/05 Javascript
vue请求数据的三种方式
2020/03/04 Javascript
python装饰器decorator介绍
2014/11/21 Python
Python计算一个文件里字数的方法
2015/06/15 Python
Apache如何部署django项目
2017/05/21 Python
Python跨文件全局变量的实现方法示例
2017/12/10 Python
使用Python做垃圾分类的原理及实例代码附源码
2019/07/02 Python
Python实现朴素贝叶斯的学习与分类过程解析
2019/08/24 Python
浅谈keras使用中val_acc和acc值不同步的思考
2020/06/18 Python
MATLAB数学建模之画图汇总
2020/07/16 Python
使用canvas对多图片拼合并导出图片的方法
2018/08/28 HTML / CSS
计算机本科生自荐信
2013/10/15 职场文书
清明节演讲稿
2014/05/27 职场文书
实习证明格式范文
2015/06/16 职场文书
2016年大学校运会广播稿件
2015/12/21 职场文书
win11无线投屏在哪设置? win11无线投屏功能的使用方法
2022/04/08 数码科技
vue里使用create, mounted调用方法
2022/04/26 Vue.js