note 51962 deleted from function.time by aidan

From: Date: Sat, 08 Oct 2005 01:03:28 +0000
Subject: note 51962 deleted from function.time by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96606@lists.php.net to get a copy of this message
Note Submitter: NOSPAM dot justin at jshewell dot com ---- This function (see the posting below) has been edited to allow for countries that don't use Daylight Savings Time and will return the time in any timezone (as specified in $TZOffset). Examples of usage: date("H:i",myDST(4,false)); //returns the time in a GCC country (no DST and 4 hours ahead of UTC) function myDST($TZOffset,$DST) { if(!isset($TZOffset)) {$TZOffset = 0;} //if the user doesn't set a timezone, use UTC //$TZOffset = 4; //GCC Timezone (UTC + 4); //echo $TZOffset; // MEZ = UTC + TZOffset: $myMEZ = mktime(gmdate("H") + $TZOffset); $myMEZ_year = date("Y", $myMEZ); $tmp = strtotime("last Sunday", mktime(0, 0, 0, 4, 1, $myMEZ_year)); $myLastSundayMarch = mktime(2, 0, 0, date("m", $tmp), date("d", $tmp), date("Y", $tmp)); $tmp = strtotime("last Sunday", mktime(0, 0, 0, 11, 1, $myMEZ_year)); $myLastSundayOctober = mktime(3, 0, 0, date("m", $tmp), date("d", $tmp), date("Y", $tmp)); if($DST) { if(($myMEZ >= $myLastSundayMarch) && ($myMEZ < $myLastSundayOctober)) { return mktime(gmdate("H") + $TZOffset + 1); // summertime } else { return mktime(gmdate("H") + $TZOffset); // normal time ("wintertime") } } else {return mktime(gmdate("H") + $TZOffset);} // no Daylight Savings Time (DST) }

« previous php.notes (#96606) next »