note 21035 added to function.localtime

From: Date: Fri, 26 Apr 2002 04:42:37 +0000
Subject: note 21035 added to function.localtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-29862@lists.php.net to get a copy of this message
I strongly suggest to do all of your developments using GMT/UTC dates & times. I provide here a version of a 'gmttime' function. Save it in a separate file and include it when needed. Please post a correction here if you find it not working for your timezone (with or without daylight saving time.). Thanks & Enjoy. ----------------------------------------------- // // File: gmttime.in-p // // Description: // Implements the gmttime function if missing from the PHP distribution // // Verifies that the function isn't already implemented if (function_exists(gmttime)) return; // // Function: gmttime // // Description: // Returns an array indexed as by the localtime() function: // - 0 or tm_sec: Seconds // - 1 or tm_min: Minutes // - 2 or tm_hour: Hour // - 3 or tm_mday: Day of the month // - 4 or tm_mon: Month of the year // - 5 or tm_year: Years since 1900 // - 6 or tm_wday: Day of the week // - 7 or tm_yday: Day of the year // - 8 or tm_isdst: Is daylight saving time in effect // - tm_fyear: Full year (only available with associative array) // // Arguments: // - Timestamp // - Boolean (for associative indexing: 0 = off, 1 = on) // // Returns: // An array on success, // false on failure. // function gmttime($dTimestamp = '', $bAssoc = 0) { // Evaluate how much difference there is between local and GTM/UTC // Don't forget to correct for daylight saving time... $aNow = localtime(); $iDelta = gmmktime(1, 1, 1, 1, 1, 1970, $aNow[8]) - mktime(1, 1, 1, 1, 1, 1970, $aNow[8]); if (!$bAssoc) { if ($dTimestamp == '') { return localtime(time() - $iDelta, 0); } else { return localtime($dTimestamp - $iDelta, 0); } } else { // For associative array, add full year index if ($dTimestamp == '') { $aGMTTime = localtime(time() - $iDelta, 1); } else { $aGMTTime = localtime($dTimestamp - $iDelta, 1); } $aGMTTime['tm_fyear'] = $aGMTTime['tm_year'] + 1900; return $aGMTTime; } // End [IF] return associative array? } // End [FUNCTION] gmttime -- http://www.php.net/manual/en/function.localtime.php http://master.php.net/manage/user-notes.php?action=edit+21035 http://master.php.net/manage/user-notes.php?action=delete+21035 http://master.php.net/manage/user-notes.php?action=reject+21035

« previous php.notes (#29862) next »