mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
157 lines
7.5 KiB
HTML
157 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.date-default-timezone-get" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">date_default_timezone_get</h1>
|
|
<p class="verinfo">(PHP 5 >= 5.1.0, PHP 7)</p><p class="refpurpose"><span class="refname">date_default_timezone_get</span> — <span class="dc-title">取得一个脚本中所有日期时间函数所使用的默认时区</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.date-default-timezone-get-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>date_default_timezone_get</strong></span>
|
|
( <span class="methodparam">void</span>
|
|
) : <span class="type">string</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
本函数返回默认时区,使用如下“假定”的顺序:
|
|
<ul class="itemizedlist">
|
|
<li class="listitem">
|
|
<p class="para">
|
|
用 <span class="function"><a href="date_default_timezone_set.html" class="function">date_default_timezone_set()</a></span>
|
|
函数设定的时区(如果设定了的话)
|
|
</p>
|
|
</li>
|
|
<li class="listitem">
|
|
<p class="para">
|
|
<em class="emphasis">仅仅</em>在 PHP 5.4.0 之前:
|
|
<var class="varname"><var class="varname">TZ</var></var> 环境变量(如果非空)
|
|
</p>
|
|
</li>
|
|
<li class="listitem">
|
|
<p class="para">
|
|
<a href="datetime.configuration.html#ini.date.timezone" class="link">date.timezone</a> 配置选项(如果设定了的话)
|
|
</p>
|
|
</li>
|
|
<li class="listitem">
|
|
<p class="para">
|
|
<em class="emphasis">仅仅</em>在 PHP 5.4.0 之前: 查询操作系统主机 (如果操作系统支持并允许)。
|
|
This uses an algorithm
|
|
that has to <em class="emphasis">guess</em> the timezone. This is by no means going to work correctly for
|
|
every situation. A warning is shown when this stage is reached. Do not rely on it to be guessed
|
|
correctly, and set <a href="datetime.configuration.html#ini.date.timezone" class="link">date.timezone</a> to the correct timezone
|
|
instead.
|
|
</p>
|
|
</li>
|
|
<li class="listitem">
|
|
<p class="para">
|
|
如果以上选择都不成功,<span class="methodname"><strong>date_default_timezone_get()</strong></span> 会则返回 <em>UTC</em> 的默认时区。
|
|
</p>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.date-default-timezone-get-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
返回一个 <span class="type"><a href="language.types.string.html" class="type string">string</a></span>。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.date-default-timezone-get-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.4.0</td>
|
|
<td>
|
|
不再使用 <em>TZ</em> 来推测时区。
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>5.4.0</td>
|
|
<td>
|
|
不再根据操作系统的信息来推测时区,因为这是不可靠的。
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.date-default-timezone-get-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-2701">
|
|
<p><strong>Example #1 获取默认时区</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'Europe/London'</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">()) {<br /> echo </span><span style="color: #DD0000">'date_default_timezone_set: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">() . </span><span style="color: #DD0000">'<br />'</span><span style="color: #007700">;<br />}<br /><br />if (</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">'date.timezone: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">);<br />}<br /><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>
|
|
date_default_timezone_set: Europe/London
|
|
date.timezone: Europe/London
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
<p class="para">
|
|
<div class="example" id="example-2702">
|
|
<p><strong>Example #2 获取一个时区的简写</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">() . </span><span style="color: #DD0000">' => ' </span><span style="color: #007700">. </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'e'</span><span style="color: #007700">) . </span><span style="color: #DD0000">' => ' </span><span style="color: #007700">. </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'T'</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>
|
|
America/Los_Angeles => America/Los_Angeles => PST
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.date-default-timezone-get-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="date_default_timezone_set.html" class="function" rel="rdfs-seeAlso">date_default_timezone_set()</a> - 设定用于一个脚本中所有日期时间函数的默认时区</span></li>
|
|
<li class="member"><a href="timezones.html" class="xref">所支持的时区列表</a></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |