Source of: /manual/en/function.date-default-timezone-get.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.datetime.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.date-default-timezone-get.php',
1 => 'date_default_timezone_get',
),
'up' =>
array (
0 => 'ref.datetime.php',
1 => 'Date/Time Functions',
),
'prev' =>
array (
0 => 'function.date-date-set.php',
1 => 'date_date_set',
),
'next' =>
array (
0 => 'function.date-default-timezone-set.php',
1 => 'date_default_timezone_set',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<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)</p><p class="refpurpose"><span class="refname">date_default_timezone_get</span> — <span class="dc-title">
Gets the default timezone used by all date/time functions in a script
</span></p>
</div>
<a name="function.date-default-timezone-get.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">string</span> <span class="methodname"><b>date_default_timezone_get</b></span>
( <span class="methodparam">void</span>
)</div>
<p class="para rdfs-comment">
In order of preference, this function returns the default timezone by:
</p><ul class="itemizedlist">
<li class="listitem">
<p class="para">
Reading the timezone set using the
<a href="function.date-default-timezone-set.php" class="function">date_default_timezone_set()</a> function (if any)
</p>
</li>
<li class="listitem">
<p class="para">
Reading the <var class="varname">TZ</var> environment variable (if non empty)
</p>
</li>
<li class="listitem">
<p class="para">
Reading the value of the <a href="datetime.configuration.php#ini.date.timezone" class="link">date.timezone</a> ini option
(if set)
</p>
</li>
<li class="listitem">
<p class="para">
Querying the host operating system (if supported and allowed by the OS)
</p>
</li>
</ul><p>
</p>
<p class="para">
If none of the above succeed, <span class="methodname"><b>date_default_timezone_get</b></span>
will return a default timezone of <i>UTC</i>.
</p>
</div>
<a name="function.date-default-timezone-get.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns a <a href="language.types.string.php" class="type string">string</a>.
</p>
</div>
<a name="function.date-default-timezone-get.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 Getting the default timezone</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><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>
</code></div>
</div>
<div class="example-contents para"><p>The above example will output
something similar to:</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>
<p class="para">
</p><div class="example">
<p><b>Example #2 Getting the abbreviation of a timezone</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><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>
</code></div>
</div>
<div class="example-contents para"><p>The above example will output:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
America/Los_Angeles => America/Los_Angeles => PST
</pre></div>
</div>
</div><p>
</p>
</div>
<a name="function.date-default-timezone-get.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.date-default-timezone-set.php" class="function" rel="rdfs-seeAlso">date_default_timezone_set()</a> - Sets the default timezone used by all date/time functions in a script</li>
<li class="member"><a href="timezones.php" class="xref">List of Supported Timezones</a></li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>