note 31133 added to function.date
| From: | jpoz at quickscribble dot com | Date: | Thu, 10 Apr 2003 20:36:05 +0000 |
| Subject: | note 31133 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46463@lists.php.net to get a copy of this message | ||
Here is a quick bit of code that will take a unix epoch date (say from a MySQL database) and allow
you to add or subtract the time zone. It will also check to see if the machine (server) is in
daylight savings or not. (This is especially helpful as I am in Missouri, but host some sites in
Arizona, which doesn't do daylight savings).
In this case the Unix epoch time is represented by "date(U)" but could easily be retieved
from a database.
$date123=date(U);
$dst=date(I); //determines whether server is in daylight savings or not, 1=yes, 0=no
if ($dst==1){
$tz="7200"; //7200 seconds = 2 hours
}
else{
$tz="3600"; //3600 seconds = 1 hour
}
$diff=$date123 - $tz; //subtract timezone diff from epoch
echo date("n-j-Y, g:i:s a", $date123);
echo date("n-j-Y, g:i:s a", $diff);
/*
results
4-10-2003, 3:26:39 pm
4-10-2003, 1:26:39 pm
*/
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+31133
http://master.php.net/manage/user-notes.php?action=delete+31133
http://master.php.net/manage/user-notes.php?action=reject+31133