php Smarty date_format [格式化时间日期]_php技巧

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()转换有效的区分符。
可以查看系统手册的有效区分符的全表.

时间: 2024-09-16 03:06:09

php Smarty date_format [格式化时间日期]_php技巧的相关文章

asp 格式化时间日期

asp教程 格式化时间日期 public function formatdt(dt, style) 'style=0 2000-10-10 下午 12:17:45 'style=1 2000-10-10 23:17:45 'style=2 2000-10-10 23:45 'style=3 00-10-10 23:45 'style=4 10-10 23:45 'style=5 2000-10-10 'style=6 00-10-10 'style=7 10-10 'style=8 23h-45

javascript 格式化时间日期函数代码脚本之家修正版_时间日期

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] javascript格式化日期时间函数_时间日期_http://www.jb51.net/article/14753.htm

JAVA格式化时间日期的简单实例_java

复制代码 代码如下: import java.util.Date;import java.text.DateFormat; /*** 格式化时间类* DateFormat.FULL = 0* DateFormat.DEFAULT = 2* DateFormat.LONG = 1* DateFormat.MEDIUM = 2* DateFormat.SHORT = 3* @author    Michael * @version   1.0, 2007/03/09*/ public class T

原生javascript实现自动更新的时间日期_javascript技巧

能够动态变化的事物总比静态的更能够吸引人,甚至更有实用效果,比如能够自动变化的时间日期效果就是如此,下面就通过代码实例介绍一下如何实现此效果,代码实例如下:一.具体代码 <html> <head> <meta charset="gb2312"> <title></title> <script type="text/javascript"> var t = null; function time(

PHP+Mysql日期时间如何转换(UNIX时间戳和格式化日期)_php技巧

写过PHP+MySQL的程序员都知道有时间差,UNIX时间戳和格式化日期是我们常打交道的两个时间表示形式,Unix时间戳存储.处理方便,但是不直观,格式化日期直观,但是处理起来不如Unix时间戳那么自如,所以有的时候需要互相转换,下面给出互相转换的几种转换方式. 一.在MySQL中完成 这种方式在MySQL查询语句中转换,优点是不占用PHP解析器的解析时间,速度快,缺点是只能用在数据库查询中,有局限性. 1. UNIX时间戳转换为日期用函数: FROM_UNIXTIME() 一般形式:selec

yii2超好用的日期组件和时间组件_php技巧

日期组件,时间组件在平时开发中是必不可少的.今天我们就来谈谈在yii2中的超好用的时间组件,也省的大家各种找js插件了. 分享之前我们先预览下效果,看看到底怎么个好用法. 当然啦,好用不好用在于自我的感觉,光看上面的图片是感受不到的.再告诉你个好消息,这两款插件已经跟yii2整合了,使用起来也是灰常的简单哦. 关于日期组件跟时间组件,前者是date('Y-m-d')类型,后者是date('Y-m-d H:i:s')类型,自然不用多说. 我们先来看看时间组件扩展 既然是扩展组建,第一步当然是安装.

优化WordPress中文章与评论的时间显示_php技巧

很多博客都喜欢用 评论发表于 "XXX 分钟 之前".文章发表于 "XXX 分钟 之前"来显示文章评论的时间,改善的时间显示方式不仅能很直观的告诉读者这篇文章或评论发表距今已有多长时间,更能增强评论回复的时间感,哥很喜欢,因为前一阵子压在手里的东西太多了,工作日白天又苦于不能上网,所以主题的样式及功能部分一点一点的写拖了好长时间,最近这阵子刚好轮到折腾评论了,所以就逐步参照网上流行的样式一点一点的修改起来自己的评论样式和功能. So-.. Go-.. 交道麻袋-..

smarty的保留变量问题_php技巧

以下是访问页面请求变量诸如get,post,cookies,server,enviroment和session变量的例子. 例如{$smarty.server.SERVER_NAME}取得服务器变量,{$smarty.env.PATH}取得系统环境变量path, {$smarty.request.username}取得get/post/cookies/server/env的复合变量. {$smarty.now}变量用于访问当前时间戳. 可以用 date_format调节器格式化输出. 例如{$s

js 格式化时间日期函数小结_时间日期

复制代码 代码如下: Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.g