[nycphp-talk] GMT -> EST or EDT
Daniel Convissor
danielc at analysisandsolutions.com
Tue Mar 2 21:45:10 EST 2004
Hi:
On Tue, Mar 02, 2004 at 08:42:51PM -0500, Christopher R. Merlo wrote:
> Have any of you had to display local time on a server that uses GMT?
> I'm searching around Google trying to figure out how best to calculate
> NY time. I don't want to just subtract 6 from the hour, because then
Ahem, you mean 4 or 5 hours for NY time.
Here's some code I made up for this purpose, though I've trimmed out stuff
that I don't believe is relevant to general use, but haven't thought of
the full ramifications of whether it's really needed or not for your
needs...
/**
* Determines if a given date/time combination is either Standard or
* Daylight time in the US Eastern Time Zone.
*
* @param string $Time time to be evaluated
* (<kbd>YYYY-MM-DD HH:MM:SS</kbd>)
*
* @return string <samp>S</samp> if Eastern STANDARD Time.
* <samp>D</samp> if Eastern DAYLIGHT Time.
* <samp>U</samp> zone couldn't be set.
*/
function getTimeType($Time) {
$z = getenv('TZ');
putenv('TZ=EST5EDT');
$Sec = strtotime($Time);
switch ( date('O', $Sec) ) {
case '-0400':
$Zone = 'D';
break;
case '-0500':
$Zone = 'S';
break;
default:
// Try this instead.
putenv('TZ=US/Eastern');
switch ( date('O', $Sec) ) {
case '-0400':
$Zone = 'D';
break;
case '-0500':
$Zone = 'S';
break;
default:
$Zone = 'U';
$this->Probs[] = 'Could not set Time Zone';
}
}
putenv("TZ=$z");
return $Zone;
}
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list