note 71147 deleted from function.gmdate by googleguy

From: Date: Tue, 22 Oct 2013 14:59:35 +0000
Subject: note 71147 deleted from function.gmdate by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197279@lists.php.net to get a copy of this message
Note Submitter: derek at d3swimming dot com ---- I don't really know what I'm doing, so I just stole various parts of this from other people around here and did a little improvising on my own. Hope this is helpful to somebody. This script allows you to insert just three variables: direction from GMT to your timezone ($sign), number of hours to your timezone ($h), and whether or not you have daylight savings time ($dst). The rest, including daylight savings time, will take care of itself (unless I don't know what I'm doing!). <?php // Get info about time zone relationship to GMT at: http://wwp.greenwichmeantime.com/ // SELECT TIME ZONE $sign = "-"; // Whichever direction from GMT to your timezone. $h = "8"; // Hour for time zone goes here e.g. +8 or -4, just remove the + or - $dst = "true"; // Just insert "true" if your location uses daylight savings time or "false" if it does not // DETECT AND ADJUST FOR DAYLIGHT SAVINGS TIME if ($dst) { $daylight_saving = date('I'); if ($daylight_saving){ if ($sign == "-"){ $h=$h-1; } else { $h=$h+1; } } } // FIND DIFFERENCE FROM GMT $hm = $h * 60; $ms = $hm * 60; // SET CURRENT TIME if ($sign == "-"){ $timestamp = time()-($ms); } else { $timestamp = time()+($ms); } // SAMPLE OUTPUT $gmdate = gmdate("m/d/Y g:i:s A", $timestamp); echo "Your current time now is : $gmdate . "; ?>

« previous php.notes (#197279) next »