php-doc-en/reference/datetime/functions/date-default-timezone-get.xml
2011-09-13 15:08:36 +00:00

175 lines
4.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.date-default-timezone-get" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>date_default_timezone_get</refname>
<refpurpose>
Gets the default timezone used by all date/time functions in a script
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>date_default_timezone_get</methodname>
<void/>
</methodsynopsis>
<para>
In order of preference, this function returns the default timezone by:
<itemizedlist>
<listitem>
<para>
Reading the timezone set using the
<function>date_default_timezone_set</function> function (if any)
</para>
</listitem>
<listitem>
<para>
Prior to PHP 5.4.0 <emphasis>only</emphasis>: Reading the <varname>TZ</varname>
environment variable (if non empty)
</para>
</listitem>
<listitem>
<para>
Reading the value of the <link linkend="ini.date.timezone">date.timezone</link> ini option
(if set)
</para>
</listitem>
<listitem>
<para>
Prior to PHP 5.4.0 <emphasis>only</emphasis>: Querying the host operating system (if supported
and allowed by the OS). This uses an algorithm
that has to <emphasis>guess</emphasis> 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 <link linkend="ini.date.timezone">date.timezone</link> to the correct timezone
instead.
</para>
</listitem>
</itemizedlist>
</para>
<para>
If none of the above succeed, <methodname>date_default_timezone_get</methodname>
will return a default timezone of <literal>UTC</literal>.
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a <type>string</type>.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.4.0</entry>
<entry>
The <literal>TZ</literal> environment variable is no longer used to
guess the timezone.
</entry>
</row>
<row>
<entry>5.4.0</entry>
<entry>
The timezone is no longer guessed from information available through the
operating system as the guessed timezone can not be relied on.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Getting the default timezone</title>
<programlisting role="php">
<![CDATA[
<?php
date_default_timezone_set('Europe/London');
if (date_default_timezone_get()) {
echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';
}
if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
date_default_timezone_set: Europe/London
date.timezone: Europe/London
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Getting the abbreviation of a timezone</title>
<programlisting role="php">
<![CDATA[
<?php
date_default_timezone_set('America/Los_Angeles');
echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T');
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
America/Los_Angeles => America/Los_Angeles => PST
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>date_default_timezone_set</function></member>
<member><xref linkend="timezones" /></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->