function.strptime.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 222 行

HTML
222
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Parse a time/date generated with strftime</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.strftime.html">strftime</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strtotime.html">strtotime</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.strptime" class="refentry">   <div class="refnamediv">    <h1 class="refname">strptime</h1>    <p class="verinfo">(PHP 5 &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">strptime</span> &mdash; <span class="dc-title">     Parse a time/date generated with <a href="function.strftime.html" class="function">strftime()</a>    </span></p>   </div>   <div class="refsect1 description">    <h3 class="title">Description</h3>    <div class="methodsynopsis dc-description">     <span class="type">array</span> <span class="methodname"><b><b>strptime</b></b></span>      ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$date</tt></span>     , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$format</tt></span>     )</div>    <p class="para rdfs-comment">     <b>strptime()</b> returns an array with the     <i><tt class="parameter">date</tt></i> parsed, or <b><tt>FALSE</tt></b> on error.    </p>    <p class="para">     Month and weekday names and other language dependent strings respect the     current locale set with <a href="function.setlocale.html" class="function">setlocale()</a> (LC_TIME).    </p>   </div>   <div class="refsect1 parameters">   <h3 class="title">Parameters</h3>   <p class="para">    <dl>     <dt>      <span class="term"><i><tt class="parameter">date</tt></i> (<a href="language.types.string.html" class="type string">string</a>)</span>      <dd>       <p class="para">        The string to parse (e.g. returned from <a href="function.strftime.html" class="function">strftime()</a>)       </p>      </dd>     </dt>     <dt>      <span class="term"><i><tt class="parameter">format</tt></i> (<a href="language.types.string.html" class="type string">string</a>)</span>      <dd>       <p class="para">        The format used in <i><tt class="parameter">date</tt></i> (e.g. the same as        used in <a href="function.strftime.html" class="function">strftime()</a>).       </p>       <p class="para">        For more information about the format options, read the        <a href="function.strftime.html" class="function">strftime()</a> page.       </p>      </dd>     </dt>    </dl>   </p>  </div>  <div class="refsect1 returnvalues">   <h3 class="title">Return Values</h3>   <p class="para">    Returns an array, or <b><tt>FALSE</tt></b> on failure.   </p>    <p class="para">     <table border="5">      <caption><b>The following parameters are returned in the array</b></caption>      <colgroup>       <thead valign="middle">        <tr valign="middle">         <th colspan="1">parameters</th>         <th colspan="1">Description</th>        </tr>       </thead>       <tbody valign="middle" class="tbody">        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_sec</td>         <td colspan="1" rowspan="1" align="left">Seconds after the minute (0-61)</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_min</td>         <td colspan="1" rowspan="1" align="left">Minutes after the hour (0-59)</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_hour</td>         <td colspan="1" rowspan="1" align="left">Hour since midnight (0-23)</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_mday</td>         <td colspan="1" rowspan="1" align="left">Day of the month (1-31)</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_mon</td>         <td colspan="1" rowspan="1" align="left">Months since January (0-11)</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_year</td>         <td colspan="1" rowspan="1" align="left">Years since 1900</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_wday</td>         <td colspan="1" rowspan="1" align="left">Days since Sunday (0-6)</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">tm_yday</td>         <td colspan="1" rowspan="1" align="left">Days since January 1 (0-365)</td>        </tr>        <tr valign="middle">         <td colspan="1" rowspan="1" align="left">unparsed</td>         <td colspan="1" rowspan="1" align="left">the <i><tt class="parameter">date</tt></i> part which was not          recognized using the specified <i><tt class="parameter">format</tt></i></td>        </tr>       </tbody>      </colgroup>     </table>    </p>  </div>  <div class="refsect1 examples">   <h3 class="title">Examples</h3>   <p class="para">   <div class="example">    <p><b>Example #1 <b>strptime()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$format&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'%d/%m/%Y&nbsp;%H:%M:%S'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$strf&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #0000BB">$format</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"$strf\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">strptime</span><span style="color: #007700">(</span><span style="color: #0000BB">$strf</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$format</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>      <div class="example-contents"><p>The above example will output something similar to:</p></div>      <div class="example-contents"><pre><div class="cdata"><pre>03/10/2004 15:54:19Array(    [tm_sec] =&gt; 19    [tm_min] =&gt; 54    [tm_hour] =&gt; 15    [tm_mday] =&gt; 3    [tm_mon] =&gt; 9    [tm_year] =&gt; 104    [tm_wday] =&gt; 0    [tm_yday] =&gt; 276    [unparsed] =&gt;)</pre></div>      </pre></div>      </div>     </p>    </div>    <div class="refsect1 notes">     <h3 class="title">Notes</h3>     <blockquote><p><b class="note">Note</b>: <span class="simpara">This function is notimplemented on Windows platforms.</span></p></blockquote>    </div>    <div class="refsect1 seealso">    <h3 class="title">See Also</h3>    <p class="para">     <ul class="simplelist">      <li class="member"><a href="function.strftime.html" class="function" rel="rdfs-seeAlso">strftime()</a></li>     </ul>    </p>   </div>  </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.strftime.html">strftime</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strtotime.html">strtotime</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?