Server EnvironmentPHP UTC in ora locale
Redhat Enterprise Linux
PHP 5.3.5
Problema
Diciamo che ho un giorno e ora UTC quali 2011-04 -27 02:45 e voglio convertire nella mia ora locale, che è America/New_York.
Tre domande:
1.) Il mio codice di seguito potrebbe risolvere il problema, sei d'accordo?
<?php
date_default_timezone_set('America/New_York'); // Set timezone.
$utc_ts = strtotime("2011-04-27 02:45"); // UTC Unix timestamp.
// Timezone offset in seconds. The offset for timezones west of UTC is always negative,
// and for those east of UTC is always positive.
$offset = date("Z");
$local_ts = $utc_ts + $offset; // Local Unix timestamp. Add because $offset is negative.
$local_time = date("Y-m-d g:i A", $local_ts); // Local time as yyyy-mm-dd h:m am/pm.
echo $local_time; // 2011-04-26 10:45 PM
?>
2.) Tuttavia, il valore di $ offset si adegua automaticamente all'ora legale (DST)?
3.) In caso contrario, come dovrei modificare il mio codice per regolare automaticamente l'ora legale?
Grazie :-)
Hai provato? – wallyk
'date (" Z ")' restituisce sempre il fuso orario 'GMT + 0000', che non ha correzioni per l'ora legale. –