📄 function.localtime.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Get the local time</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.idate.html">idate</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.microtime.html">microtime</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.localtime" class="refentry"> <div class="refnamediv"> <h1 class="refname">localtime</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">localtime</span> — <span class="dc-title">Get the local time</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>localtime</b></b></span> ([ <span class="methodparam"><span class="type">int</span> <tt class="parameter">$timestamp</tt></span> [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$is_associative</tt></span> ]] )</div> <p class="para rdfs-comment"> The <b>localtime()</b> function returns an array identical to that of the structure returned by the C function call. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt><span class="term"><i><tt class="parameter">timestamp</tt></i></span><dd><p class="para">The optional <i><tt class="parameter">timestamp</tt></i> parameter is an <a href="language.types.integer.html" class="type integer">integer</a> Unix timestamp that defaults to the currentlocal time if a <i><tt class="parameter">timestamp</tt></i> is not given. In other words, it defaults to the value of <a href="function.time.html" class="function">time()</a>. </p></dd></dt> <dt> <span class="term"><i><tt class="parameter">is_associative</tt></i></span> <dd> <p class="para"> If set to <b><tt>FALSE</tt></b> or not supplied then the array is returned as a regular, numerically indexed array. If the argument is set to <b><tt>TRUE</tt></b> then <b>localtime()</b> returns an associative array containing all the different elements of the structure returned by the C function call to localtime. The names of the different keys of the associative array are as follows: </p> <p class="para"> <ul class="itemizedlist"> <li class="listitem"> <span class="simpara"> "tm_sec" - seconds </span> </li> <li class="listitem"> <span class="simpara"> "tm_min" - minutes </span> </li> <li class="listitem"> <span class="simpara"> "tm_hour" - hour </span> </li> <li class="listitem"> <span class="simpara"> "tm_mday" - day of the month </span> <span class="simpara"> Months are from 0 (Jan) to 11 (Dec) and days of the week are from 0 (Sun) to 6 (Sat). </span> </li> <li class="listitem"> <span class="simpara"> "tm_mon" - month of the year, starting with 0 for January </span> </li> <li class="listitem"> <span class="simpara"> "tm_year" - Years since 1900 </span> </li> <li class="listitem"> <span class="simpara"> "tm_wday" - Day of the week </span> </li> <li class="listitem"> <span class="simpara"> "tm_yday" - Day of the year </span> </li> <li class="listitem"> <span class="simpara"> "tm_isdst" - Is daylight savings time in effect </span> </li> </ul> </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para">Every call to a date/time function will generate a <b><tt>E_NOTICE</tt></b> if the time zone is not valid, and/or a <b><tt>E_STRICT</tt></b> messageif using the system settings or the <var class="varname">TZ</var> environmentvariable. See also <a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"><td colspan="1" rowspan="1" align="left">5.1.0</td><td colspan="1" rowspan="1" align="left"><p class="para">Now issues the <b><tt>E_STRICT</tt></b> and <b><tt>E_NOTICE</tt></b> time zone errors.</p></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>localtime()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$localtime </span><span style="color: #007700">= </span><span style="color: #0000BB">localtime</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$localtime_assoc </span><span style="color: #007700">= </span><span style="color: #0000BB">localtime</span><span style="color: #007700">(</span><span style="color: #0000BB">time</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$localtime</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$localtime_assoc</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></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>Array( [0] => 24 [1] => 3 [2] => 19 [3] => 3 [4] => 3 [5] => 105 [6] => 0 [7] => 92 [8] => 1)Array( [tm_sec] => 24 [tm_min] => 3 [tm_hour] => 19 [tm_mday] => 3 [tm_mon] => 3 [tm_year] => 105 [tm_wday] => 0 [tm_yday] => 92 [tm_isdst] => 1)</pre></div> </pre></div> </div> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.idate.html">idate</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.microtime.html">microtime</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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -