mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
212 lines
7.5 KiB
HTML
212 lines
7.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>取得本地时间</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.localtime" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">localtime</h1>
|
|
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">localtime</span> — <span class="dc-title">取得本地时间</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.localtime-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>localtime</strong></span>
|
|
([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code><span class="initializer"> = time()</span></span>
|
|
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_associative</code><span class="initializer"> = false</span></span>
|
|
]] ) : <span class="type">array</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
<span class="function"><strong>localtime()</strong></span> 函数返回一个数组,其结构和
|
|
C 函数调用返回的完全一样。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.localtime-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">timestamp</code></dt>
|
|
<dd>
|
|
<p class="para">
|
|
可选的 <code class="parameter">timestamp</code> 参数是一个 <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> 的 Unix
|
|
时间戳,如未指定,参数值默认为当前本地时间。也就是说,其值默认为
|
|
<span class="function"><a href="time.html" class="function">time()</a></span> 的返回值。</p></dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">is_associative</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
如果设为 <strong><code>FALSE</code></strong>
|
|
或未提供则返回的是普通的数字索引数组。如果该参数设为 <strong><code>TRUE</code></strong> 则
|
|
<span class="function"><strong>localtime()</strong></span> 函数返回包含有所有从
|
|
C 的 localtime 函数调用所返回的不同单元的关联数组。关联数组中不同的键名为:
|
|
</p>
|
|
<p class="para">
|
|
<ul class="itemizedlist">
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_sec" - 秒数, <em>0</em> 到 <em>59</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_min" - 分钟数, <em>0</em> 到 <em>59</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_hour" - 小时, <em>0</em> 到 <em>23</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_mday" - 月份中的第几日, <em>1</em> 到 <em>31</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_mon" - 年份中的第几个月, <em>0</em> (Jan) 到 <em>11</em> (Dec)
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_year" - 年份,从 1900 开始
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_wday" - 星期中的第几天, <em>0</em> (Sun) 到 <em>6</em> (Sat)
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_yday" - 一年中的第几天, <em>0</em> 到 <em>365</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"tm_isdst" - 夏令时当前是否生效?
|
|
</span>
|
|
<span class="simpara">
|
|
如果是生效的是正数, <em>0</em> 代表未生效,负数代表未知。
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 errors" id="refsect1-function.localtime-errors">
|
|
<h3 class="title">错误/异常</h3>
|
|
|
|
<p class="para">
|
|
在每 次调用日期/时间函数时,如果时区无效则会引发 <strong><code>E_NOTICE</code></strong> 错误,如果使用系统设定值或 <var class="varname"><var class="varname">TZ</var></var>
|
|
环境变量,则会引发 <strong><code>E_STRICT</code></strong> 或 <strong><code>E_WARNING</code></strong> 消息。参见
|
|
<span class="function"><a href="date_default_timezone_set.html" class="function">date_default_timezone_set()</a></span>。</p>
|
|
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.localtime-changelog">
|
|
<h3 class="title">更新日志</h3>
|
|
<p class="para">
|
|
<table class="doctable informaltable">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>版本</th>
|
|
<th>说明</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
|
|
<tr><td>5.1.0</td><td><p class="para">
|
|
现在发布 <strong><code>E_STRICT</code></strong> 和 <strong><code>E_NOTICE</code></strong>
|
|
时区错误。</p></td></tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.localtime-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-2725">
|
|
<p><strong>Example #1 <span class="function"><strong>localtime()</strong></span> 例子</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><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>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
|
|
<div class="example-contents screen">
|
|
<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>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.localtime-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="getdate.html" class="function" rel="rdfs-seeAlso">getdate()</a> - 取得日期/时间信息</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |