date_default_timezone_setSETS the default timezone used by all date/time functions in a script.
<?php
bool date_default_timezone_set ( str $timezoneId )
where,
$timezoneId = The timezone Identifier
( SEE the below TABLE )
( EXERCISE number 1 )
?>
$timezoneId
The $timezoneId as returned by the function timezone_identifiers_list.
This function returns FALSE if the $timezoneId isn't valid, or TRUE otherwise.
A timezone basically is a region of the Earth that presents uniformity in the measurement of time for legal, commercial or social purposes.
Standard timezones can be defined by dividing the spheroidal surface of the Earth into 24 buds, with Greenwich meredian as a reference.
timezones are important in handling dates and time as well as in the preparation of calendars.
To verify the use of this function date_default_timezone_get.
EXERCISE
<style>
tr { background:#fff; font-size:12px;}
.azb { background-color:#00CCFF; font-size:12px;}
.ctr { text-align:center; }
</style>
<table align="center" width="100%" cellspacing="5"
cellpadding="5" border="1"><tr>
<td class="azb" width="50%">Timezone NAME</td>
<td class="azb" width="50%">Timezone NAME</td></tr>
<?php
$arr_timez_id_lst1 = timezone_identifiers_list();
$tzn = count($arr_timez_id_lst1);
$tzn = ($tzn-1);
for($xs = 0; $xs <= $tzn - 1; $xs++)
{
echo '<td>' . $arr_timez_id_lst1[$xs++] . '</td>';
echo '<td>' . $arr_timez_id_lst1[$xs++] . '</td></tr>';
}
?>
<tr><td class="azb ctr" colspan="2">ed48</td></tr></table>
EXERCISE
<?php
$lang = 'jp';
$tzID02 = 'Asia/Tokyo';
$tzOK02 = date_default_timezone_set($tzID02);
if ($tzOK02 == true)
{
$jp = 'タイムゾーンセット: ';
echo '<br>' . $$lang . '<br><br>'
. $tzID02;
}
else
{
$jp = '希望するタイムゾーンを確立することができません.';
echo $$lang;
}
// This TIMEZONE remains active
// until the establishment of another
?>
EXERCISE
<?php
// $lang = 'pt';
$lang = 'en';
// $lang = 'jp';
$tzID03 = 'America/Sao_Paulo';
$tzOK03 = date_default_timezone_set($tzID03);
if ($tzOK03 == true)
{
$pt = 'Fuso horário estabelecido: ';
$en = 'Time zone set: ';
$jp = 'タイムゾーンセット: ';
echo '<br>' . $$lang . '<br><br>'
. $tzID03;
}
else
{
$pt = 'Não foi possivel estabelecer o Fuso horário desejado.';
$en = 'Unable to establish the desired Time Zone.';
$jp = '希望するタイムゾーンを確立することができません.';
echo $$lang;
}
?>
EXERCISE
<?php
// $lang = 'jp';
// $lang = 'pt';
$lang = 'en';
$tzID04 = 'America/Foo';
$tzOK04 = @date_default_timezone_set($tzID04);
if ($tzOK04 == true)
{
$pt = 'Fuso horário estabelecido: ';
$en = 'Time zone set: ';
$jp = 'タイムゾーンセット: ';
echo '<br>' . $$lang . '<br><br>'
. $tzID04;
}
else
{
$pt = 'Não foi possivel estabelecer o Fuso horário desejado.';
$en = 'Unable to establish the desired Time Zone.';
$jp = '希望するタイムゾーンを確立することができません.';
echo $$lang;
}
?>