mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
133 lines
5.8 KiB
HTML
133 lines
5.8 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-set" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">date_default_timezone_set</h1>
|
|
<p class="verinfo">(PHP 5 >= 5.1.0, PHP 7)</p><p class="refpurpose"><span class="refname">date_default_timezone_set</span> — <span class="dc-title">设定用于一个脚本中所有日期时间函数的默认时区</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.date-default-timezone-set-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>date_default_timezone_set</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$timezone_identifier</code></span>
|
|
) : <span class="type">bool</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
<span class="function"><strong>date_default_timezone_set()</strong></span> 设定用于所有日期时间函数的默认时区。
|
|
</p>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
自 PHP 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条
|
|
<strong><code>E_NOTICE</code></strong> 级别的错误信息,如果使用系统设定或
|
|
<var class="varname"><var class="varname">TZ</var></var> 环境变量则还会产生 <strong><code>E_STRICT</code></strong> 级别的信息。
|
|
</p>
|
|
</p></blockquote>
|
|
<p class="para">
|
|
除了用此函数,你还可以通过 INI 设置 <a href="datetime.configuration.html#ini.date.timezone" class="link">date.timezone</a> 来设置默认时区。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.date-default-timezone-set-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">timezone_identifier</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
时区标识符,例如 <em>UTC</em> 或
|
|
<em>Europe/Lisbon</em>。合法标识符列表见<a href="timezones.html" class="xref">所支持的时区列表</a>。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.date-default-timezone-set-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
如果 <code class="parameter">timezone_identifier</code> 参数无效则返回 <strong><code>FALSE</code></strong>,否则返回 <strong><code>TRUE</code></strong>。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.date-default-timezone-set-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-2703">
|
|
<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">'America/Los_Angeles'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$script_tz </span><span style="color: #007700">= </span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">();<br /><br />if (</span><span style="color: #0000BB">strcmp</span><span style="color: #007700">(</span><span style="color: #0000BB">$script_tz</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 /> echo </span><span style="color: #DD0000">'Script timezone differs from ini-set timezone.'</span><span style="color: #007700">;<br />} else {<br /> echo </span><span style="color: #DD0000">'Script timezone and ini-set timezone match.'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.date-default-timezone-set-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.3.0</td>
|
|
<td>
|
|
现在会抛出 <strong><code>E_WARNING</code></strong> 而不是
|
|
<strong><code>E_STRICT</code></strong>。
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>5.1.2</td>
|
|
<td>本版本开始验证 <code class="parameter">timezone_identifier</code> 参数。
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.date-default-timezone-set-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="date_default_timezone_get.html" class="function" rel="rdfs-seeAlso">date_default_timezone_get()</a> - 取得一个脚本中所有日期时间函数所使用的默认时区</span></li>
|
|
<li class="member"><a href="timezones.html" class="xref">所支持的时区列表</a></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |