<!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>Sets the default timezone used by all date/time functions in a script</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.date-default-timezone-get.html">date_default_timezone_get</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.date-diff.html">date_diff</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><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)</p><p class="refpurpose"><span class="refname">date_default_timezone_set</span> — <span class="dc-title"> Sets the default timezone used by all date/time functions in a script </span></p> </div> <div class="refsect1 description" id="refsect1-function.date-default-timezone-set-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <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> )</div> <p class="para rdfs-comment"> <span class="function"><strong>date_default_timezone_set()</strong></span> sets the default timezone used by all date/time functions. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Since PHP 5.1.0 (when the date/time functions were rewritten), every call to a date/time function will generate a <strong><code>E_NOTICE</code></strong> if the timezone isn't valid, and/or a <strong><code>E_WARNING</code></strong> message if using the system settings or the <var class="varname"><var class="varname">TZ</var></var> environment variable. </p> </p></blockquote> <p class="para"> Instead of using this function to set the default timezone in your script, you can also use the INI setting <a href="datetime.configuration.html#ini.date.timezone" class="link">date.timezone</a> to set the default timezone. </p> </div> <div class="refsect1 parameters" id="refsect1-function.date-default-timezone-set-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">timezone_identifier</code></em></span> <dd> <p class="para"> The timezone identifier, like <em>UTC</em> or <em>Europe/Lisbon</em>. The list of valid identifiers is available in the <a href="timezones.html" class="xref">List of Supported Timezones</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.date-default-timezone-set-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> This function returns <strong><code>FALSE</code></strong> if the <em><code class="parameter">timezone_identifier</code></em> isn't valid, or <strong><code>TRUE</code></strong> otherwise. </p> </div> <div class="refsect1 examples" id="refsect1-function.date-default-timezone-set-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2295"> <p><strong>Example #1 Getting the default timezone</strong></p> <div class="example-contents"> <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 /><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> </code></div> </div> </div> </p> </div> <div class="refsect1 changelog" id="refsect1-function.date-default-timezone-set-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.3.0</td> <td> Now throws <strong><code>E_WARNING</code></strong> rather than <strong><code>E_STRICT</code></strong>. </td> </tr> <tr> <td>5.1.2</td> <td> The function started to validate the <em><code class="parameter">timezone_identifier</code></em> parameter. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-function.date-default-timezone-set-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.date-default-timezone-get.html" class="function" rel="rdfs-seeAlso">date_default_timezone_get()</a> - Gets the default timezone used by all date/time functions in a script</span></li> <li class="member"><a href="timezones.html" class="xref">List of Supported Timezones</a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.date-default-timezone-get.html">date_default_timezone_get</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.date-diff.html">date_diff</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>