Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 4595

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>strftime</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Date/Time 日期/时间函数"
HREF="ref.datetime.html"><LINK
REL="PREVIOUS"
TITLE="mktime"
HREF="function.mktime.html"><LINK
REL="NEXT"
TITLE="strptime"
HREF="function.strptime.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.mktime.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.strptime.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.strftime"
></A
>strftime</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN29804"
></A
><P
>    (PHP 3, PHP 4, PHP 5)</P
>strftime&nbsp;--&nbsp;根据区域设置格式化本地时间/日期</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN29807"
></A
><H2
>说明</H2
>string <B
CLASS="methodname"
>strftime</B
> ( string format [, int timestamp] )<BR
></BR
><P
>&#13;   返回用给定的格式字串对给出的 <CODE
CLASS="parameter"
>timestamp</CODE
>
   进行格式输出后的字符串。如果没有给出时间戳则用当前的本地时间。月份和星期几以及其它和语言有关的字符串写法和用
   <A
HREF="function.setlocale.html"
><B
CLASS="function"
>setlocale()</B
></A
> 设定的当前的区域有关。
  </P
><P
>&#13;   格式字串能识别下列转换标记:
   <P
></P
><UL
><LI
><P
>&#13;      %a - 当前区域星期几的简写
     </P
></LI
><LI
><P
>&#13;      %A - 当前区域星期几的全称
     </P
></LI
><LI
><P
>&#13;      %b - 当前区域月份的简写
     </P
></LI
><LI
><P
>&#13;      %B - 当前区域月份的全称
     </P
></LI
><LI
><P
>&#13;      %c - 当前区域首选的日期时间表达
     </P
></LI
><LI
><P
>&#13;      %C - 世纪值(年份除以 100 后取整,范围从 00 到 99)
     </P
></LI
><LI
><P
>&#13;      %d - 月份中的第几天,十进制数字(范围从 01 到 31)
     </P
></LI
><LI
><P
>&#13;      %D - 和 %m/%d/%y 一样
     </P
></LI
><LI
><P
>&#13;      %e - 月份中的第几天,十进制数字,一位的数字前会加上一个空格(范围从 ' 1' 到 '31')
     </P
></LI
><LI
><P
>&#13;      %g - 和 %G 一样,但是没有世纪
     </P
></LI
><LI
><P
>&#13;      %G - 4 位数的年份,符合 ISO 星期数(参见
      %V)。和 %V 的格式和值一样,只除了如果 ISO
      星期数属于前一年或者后一年,则使用那一年。
     </P
></LI
><LI
><P
>&#13;      %h - 和 %b 一样
     </P
></LI
><LI
><P
>&#13;      %H - 24 小时制的十进制小时数(范围从 00 到 23)
     </P
></LI
><LI
><P
>&#13;      %I - 12 小时制的十进制小时数(范围从 00 到 12)
    </P
></LI
><LI
><P
>&#13;      %j - 年份中的第几天,十进制数(范围从  001 到 366)
     </P
></LI
><LI
><P
>&#13;      %m - 十进制月份(范围从 01 到 12)
     </P
></LI
><LI
><P
>&#13;      %M - 十进制分钟数
     </P
></LI
><LI
><P
>&#13;      %n - 换行符
     </P
></LI
><LI
><P
>&#13;      %p - 根据给定的时间值为 `am' 或 `pm',或者当前区域设置中的相应字符串
     </P
></LI
><LI
><P
>&#13;      %r - 用 a.m. 和 p.m. 符号的时间
     </P
></LI
><LI
><P
>&#13;      %R - 24 小时符号的时间
     </P
></LI
><LI
><P
>&#13;      %S - 十进制秒数
     </P
></LI
><LI
><P
>&#13;      %t - 制表符
     </P
></LI
><LI
><P
>&#13;      %T - 当前时间,和 %H:%M:%S 一样
     </P
></LI
><LI
><P
>&#13;      %u - 星期几的十进制数表达 [1,7],1 表示星期一
     </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>警告</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;       尽管 ISO 9889:1999(当前的 C 标准)明确指出一周从星期一开始,但是
       Sun Solaris 的一周似乎从星期天开始并作为 1。
      </P
></TD
></TR
></TABLE
></DIV
></LI
><LI
><P
>&#13;      %U - 本年的第几周,从第一周的第一个星期天作为第一天开始
     </P
></LI
><LI
><P
>&#13;      %V - 本年第几周的 ISO 8601:1988 格式,范围从 01 到 53,第
      1 周是本年第一个至少还有 4 天的星期,星期一作为每周的第一天。(用
      %G 或者 %g 作为指定时间戳相应周数的年份组成。)
     </P
></LI
><LI
><P
>&#13;      %W - 本年的第几周数,从第一周的第一个星期一作为第一天开始
     </P
></LI
><LI
><P
>&#13;      %w - 星期中的第几天,星期天为 0
     </P
></LI
><LI
><P
>&#13;      %x - 当前区域首选的时间表示法,不包括时间
     </P
></LI
><LI
><P
>&#13;      %X - 当前区域首选的时间表示法,不包括日期
     </P
></LI
><LI
><P
>&#13;      %y - 没有世纪数的十进制年份(范围从 00 到 99)
     </P
></LI
><LI
><P
>&#13;      %Y - 包括世纪数的十进制年份
     </P
></LI
><LI
><P
>&#13;      %Z 或 %z - 时区名或缩写
     </P
></LI
><LI
><P
>&#13;      %% - 文字上的 `%' 字符
     </P
></LI
></UL
>
   <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
     可能不是所有的转换标记都被 C 库文件支持,这种情况下 PHP
     的 <B
CLASS="function"
>strftime()</B
>
     也不支持。此外,不是所有的平台都支持负的时间戳,因此日期的范围可能限定在不早于
     Unix 纪元。这意味着例如
     %e, %T,%R 和 %D(可能更多)以及早于
     <TT
CLASS="literal"
>Jan 1, 1970</TT
> 的时间在 Windows,一些 Linux
     发行版本,以及其它几个操作系统中无效。对于 Windows
     系统,所支持的转换标记可在
     <A
HREF="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp"
TARGET="_top"
><ACRONYM
CLASS="acronym"
>MSDN</ACRONYM
> 网站</A
>找到。
    </P
></BLOCKQUOTE
></DIV
>
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN29901"
></A
><P
><B
>例 1. <B
CLASS="function"
>strftime()</B
> 区域的例子</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_TIME</font><font color="#007700">, </font><font color="#DD0000">"C"</font><font color="#007700">);<br />echo </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%A"</font><font color="#007700">);<br /></font><font color="#0000BB">setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_TIME</font><font color="#007700">, </font><font color="#DD0000">"fi_FI"</font><font color="#007700">);<br />echo </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">" in Finnish is %A,"</font><font color="#007700">);<br /></font><font color="#0000BB">setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_TIME</font><font color="#007700">, </font><font color="#DD0000">"fr_FR"</font><font color="#007700">);<br />echo </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">" in French %A and"</font><font color="#007700">);<br /></font><font color="#0000BB">setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_TIME</font><font color="#007700">, </font><font color="#DD0000">"de_DE"</font><font color="#007700">);<br />echo </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">" in German %A.\n"</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   本例在你的系统中安装有各自的区域设置后才能工作。
   <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
     %G 和 %V,如果数字编号系统未能充分理解,基于 ISO 8601:1988
     的星期数可能得出未预期的结果。见上面的 %V 和以下的例子。
    </P
></BLOCKQUOTE
></DIV
>
    <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN29907"
></A
><P
><B
>例 2. ISO 8601:1988 week number example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;December 2002 / January 2003<br />ISOWk&nbsp;&nbsp;M&nbsp;&nbsp;&nbsp;Tu&nbsp;&nbsp;W&nbsp;&nbsp;&nbsp;Thu F&nbsp;&nbsp;&nbsp;Sa&nbsp;&nbsp;Su<br />----- ----------------------------<br />51&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16&nbsp;&nbsp;17&nbsp;&nbsp;18&nbsp;&nbsp;19&nbsp;&nbsp;20&nbsp;&nbsp;21&nbsp;&nbsp;22<br />52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;23&nbsp;&nbsp;24&nbsp;&nbsp;25&nbsp;&nbsp;26&nbsp;&nbsp;27&nbsp;&nbsp;28&nbsp;&nbsp;29<br />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;5<br />2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;10&nbsp;&nbsp;11&nbsp;&nbsp;12<br />3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13&nbsp;&nbsp;14&nbsp;&nbsp;15&nbsp;&nbsp;16&nbsp;&nbsp;17&nbsp;&nbsp;18&nbsp;&nbsp;19&nbsp;&nbsp;&nbsp;*/<br /><br />// Outputs: 12/28/2002 - %V,%G,%Y = 52,2002,2002<br /></font><font color="#007700">echo </font><font color="#DD0000">"12/28/2002 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">, </font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"12/28/2002"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Outputs: 12/30/2002 - %V,%G,%Y = 1,2003,2002<br /></font><font color="#007700">echo </font><font color="#DD0000">"12/30/2002 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">, </font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"12/30/2002"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Outputs: 1/3/2003 - %V,%G,%Y = 1,2003,2003<br /></font><font color="#007700">echo </font><font color="#DD0000">"1/3/2003 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">,</font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"1/3/2003"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Outputs: 1/10/2003 - %V,%G,%Y = 2,2003,2003<br /></font><font color="#007700">echo </font><font color="#DD0000">"1/10/2003 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">,</font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"1/10/2003"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /><br /><br /></font><font color="#FF8000">/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;December 2004 / January 2005<br />ISOWk&nbsp;&nbsp;M&nbsp;&nbsp;&nbsp;Tu&nbsp;&nbsp;W&nbsp;&nbsp;&nbsp;Thu F&nbsp;&nbsp;&nbsp;Sa&nbsp;&nbsp;Su<br />----- ----------------------------<br />51&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13&nbsp;&nbsp;14&nbsp;&nbsp;15&nbsp;&nbsp;16&nbsp;&nbsp;17&nbsp;&nbsp;18&nbsp;&nbsp;19<br />52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;21&nbsp;&nbsp;22&nbsp;&nbsp;23&nbsp;&nbsp;24&nbsp;&nbsp;25&nbsp;&nbsp;26<br />53&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;27&nbsp;&nbsp;28&nbsp;&nbsp;29&nbsp;&nbsp;30&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;2<br />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;9<br />2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;11&nbsp;&nbsp;12&nbsp;&nbsp;13&nbsp;&nbsp;14&nbsp;&nbsp;15&nbsp;&nbsp;16&nbsp;&nbsp;&nbsp;*/<br /><br />// Outputs: 12/23/2004 - %V,%G,%Y = 52,2004,2004<br /></font><font color="#007700">echo </font><font color="#DD0000">"12/23/2004 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">,</font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"12/23/2004"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Outputs: 12/31/2004 - %V,%G,%Y = 53,2004,2004<br /></font><font color="#007700">echo </font><font color="#DD0000">"12/31/2004 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">,</font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"12/31/2004"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Outputs: 1/2/2005 - %V,%G,%Y = 53,2004,2005<br /></font><font color="#007700">echo </font><font color="#DD0000">"1/2/2005 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">,</font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"1/2/2005"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Outputs: 1/3/2005 - %V,%G,%Y = 1,2005,2005<br /></font><font color="#007700">echo </font><font color="#DD0000">"1/3/2005 - %V,%G,%Y = " </font><font color="#007700">. </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%V,%G,%Y"</font><font color="#007700">,</font><font color="#0000BB">strtotime</font><font color="#007700">(</font><font color="#DD0000">"1/3/2005"</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
><P
>&#13;   参见 <A
HREF="function.setlocale.html"
><B
CLASS="function"
>setlocale()</B
></A
>,<A
HREF="function.mktime.html"
><B
CLASS="function"
>mktime()</B
></A
>,<A
HREF="function.strptime.html"
><B
CLASS="function"
>strptime()</B
></A
>
   以及 <A
HREF="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html"
TARGET="_top"
>Open Group specification of
   <B
CLASS="function"
>strftime()</B
></A
>。
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.mktime.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.strptime.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>mktime</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.datetime.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>strptime</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>