downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

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 &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">date_default_timezone_get</span> &mdash; <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">&lt;?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&nbsp;(</span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'date_default_timezone_set:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">;<br />}<br /><br />if&nbsp;(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'date.timezone:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</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">?&gt;</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">&lt;?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&nbsp;</span><span style="color: #0000BB">date_default_timezone_get</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;=&gt;&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'e'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;=&gt;&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</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">?&gt;</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 =&gt; America/Los_Angeles =&gt; 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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites