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 相关文章推荐
深入for,while,foreach遍历时间比较的详解
Jun 08 PHP
兼容各大浏览器带关闭按钮的漂浮多组图片广告代码
Jun 05 PHP
PHP大转盘中奖概率算法实例
Oct 21 PHP
十幅图告诉你什么是PHP引用
Feb 22 PHP
Yii中CArrayDataProvider和CActiveDataProvider区别实例分析
Mar 02 PHP
PHP+JQuery+Ajax实现分页方法详解
Aug 06 PHP
PHP入门教程之面向对象基本概念实例分析
Sep 11 PHP
PHP常用的三种设计模式
Feb 17 PHP
详解php 使用Callable Closure强制指定回调类型
Oct 26 PHP
PHP封装的简单连接MongoDB类示例
Feb 13 PHP
4种Windows系统下Laravel框架的开发环境安装及部署方法详解
Apr 06 PHP
tp5使用layui实现多个图片上传(带附件选择)的方法实例
Nov 17 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
桌面中心(三)修改数据库
2006/10/09 PHP
PHP数组游标实现对数组的各种操作详解
2016/01/26 PHP
PHP7扩展开发之基于函数方式使用lib库的方法详解
2018/01/15 PHP
WordPress伪静态规则设置代码实例
2020/12/10 PHP
javascript flash下fromCharCode和charCodeAt方法使用说明
2008/01/12 Javascript
jquery获取URL中参数解决中文乱码问题的两种方法
2013/12/18 Javascript
JQuery中阻止事件冒泡几种方式及其区别介绍
2014/01/15 Javascript
jquery实现点击label的同时触发文本框点击事件的方法
2015/06/05 Javascript
angular.js分页代码的实例
2016/07/27 Javascript
EasyUI的doCellTip实现鼠标放到单元格上提示单元格内容
2016/08/24 Javascript
JavaScript实现隐藏省略文字效果的方法
2017/04/27 Javascript
jquery dataTable 获取某行数据
2017/05/05 jQuery
如何从0开始用node写一个自己的命令行程序
2018/12/29 Javascript
vue-router 起步步骤详解
2019/03/26 Javascript
Layui 动态禁止select下拉的例子
2019/09/03 Javascript
vue3.0中使用element的完整步骤
2021/03/04 Vue.js
[02:23]2014DOTA2国际邀请赛中国战队回顾
2014/08/01 DOTA
Python中decorator使用实例
2015/04/14 Python
python的文件操作方法汇总
2017/11/10 Python
Python中循环引用(import)失败的解决方法
2018/04/22 Python
关于python3中setup.py小概念解析
2019/08/22 Python
django中cookiecutter的使用教程
2020/12/03 Python
HTML5 video循环播放多个视频的方法步骤
2020/08/06 HTML / CSS
若干个Java基础面试题
2015/05/19 面试题
应届毕业生个人自我评价
2013/09/20 职场文书
销售会计工作职责
2013/12/02 职场文书
运动会致辞稿50字
2014/02/04 职场文书
公司担保书格式范文
2014/05/12 职场文书
思想作风整顿个人剖析材料
2014/10/06 职场文书
英语感谢信范文
2015/01/20 职场文书
西柏坡导游词
2015/02/05 职场文书
舌尖上的中国观后感
2015/06/02 职场文书
社区志愿服务活动感想
2015/08/07 职场文书
2016春节放假通知范文
2015/08/18 职场文书
中学生打架检讨书之500字
2019/08/06 职场文书
Redis Cluster 字段模糊匹配及删除
2021/05/27 Redis