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 相关文章推荐
我的论坛源代码(一)
Oct 09 PHP
测试您的 PHP 水平的题目
May 30 PHP
PHP IE中下载附件问题解决方法
Jan 07 PHP
Drupal读取Excel并导入数据库实例
Mar 02 PHP
php中静态类与静态变量用法的区别分析
Jan 15 PHP
php绘图之在图片上写中文和英文的方法
Jan 24 PHP
php从给定url获取文件扩展名的方法
Mar 14 PHP
为百度UE编辑器上传图片添加水印功能
Apr 16 PHP
php正则去除网页中所有的html,js,css,注释的实现方法
Nov 03 PHP
ThinkPHP 模板引擎使用详解
May 07 PHP
Laravel5.1 框架数据库操作DB运行原生SQL的方法分析
Jan 07 PHP
详解PHP中curl_multi并发的实现
Jun 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开发过程中常用函数收藏
2009/12/14 PHP
php实现将字符串按照指定距离进行分割的方法
2015/03/14 PHP
JQuery 选择器 xpath 语法应用
2010/05/13 Javascript
jquery trim() 功能源代码
2011/02/14 Javascript
关于event.cancelBubble和event.stopPropagation()的区别介绍
2011/12/11 Javascript
js的onload事件及初始化按钮事件示例代码
2013/09/25 Javascript
js/jquery判断浏览器类型的方法小结
2015/05/12 Javascript
jQuery增加自定义函数的方法
2015/07/18 Javascript
第二次聊一聊JS require.js模块化工具的基础知识
2016/04/17 Javascript
浅谈JavaScript中小数和大整数的精度丢失
2016/05/31 Javascript
浅谈$_FILES数组为空的原因
2017/02/16 Javascript
vue基于Vue2.0和高德地图的地图组件实例
2017/04/28 Javascript
微信小程序url与token设置详解
2017/09/26 Javascript
Angular实现的敏感文字自动过滤与提示功能示例
2017/12/29 Javascript
nodejs基于WS模块实现WebSocket聊天功能的方法
2018/01/12 NodeJs
Angular2.0实现modal对话框的方法示例
2018/02/18 Javascript
基于vue-ssr的静态网站生成器VuePress 初体验
2018/04/17 Javascript
vue与iframe之间的信息交互的实现
2020/04/08 Javascript
JS实现多选框的操作
2020/06/24 Javascript
python计算文本文件行数的方法
2015/07/06 Python
详解Python pygame安装过程笔记
2017/06/05 Python
关于Python中空格字符串处理的技巧总结
2017/08/10 Python
Java分治归并排序算法实例详解
2017/12/12 Python
tensorflow saver 保存和恢复指定 tensor的实例讲解
2018/07/26 Python
python命令行参数用法实例分析
2019/06/25 Python
Python PIL库图片灰化处理
2020/04/07 Python
keras 自定义loss model.add_loss的使用详解
2020/06/22 Python
完美解决keras 读取多个hdf5文件进行训练的问题
2020/07/01 Python
程序设计HTML5 Canvas API
2013/04/08 HTML / CSS
伊芙丽官方旗舰店:中国淑女一线品牌
2017/12/01 全球购物
开工仪式策划方案
2014/05/23 职场文书
建筑安全标语
2014/06/07 职场文书
教师查摆问题及整改措施
2014/10/11 职场文书
颐和园的导游词
2015/01/30 职场文书
CSS变量实现主题切换的方法
2021/06/23 HTML / CSS
CSS中calc(100%-100px)不加空格不生效
2023/05/07 HTML / CSS