note 51706 added to function.gmdate
| From: | wynnesome at osu1 dot php dot net | Date: | Fri, 08 Apr 2005 04:40:26 +0000 |
| Subject: | note 51706 added to function.gmdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87686@lists.php.net to get a copy of this message | ||
I want to thank www.l-serwis.wpt.pl for the
$zone=3600*0 //GMT
$zone=3600*1 //CET
$zone=3600*-5//USA
$date=gmdate("D M Y H:i", time() + $zone);
solution a few posts up, which worked for me where the (putenv) and a couple of other functions
discussed here and elsewhere were not bringing back anything but GMT time when I tried them.
I have a web site supporting a local retail store, and most if not all posts to my guestbook will be
coming from the local area, so it makes much more sense to be able to have the posts shown in local
time instead of GMT or the server's TZ.
For my site, I modified the displayed date format, and also instead of setting a fixed time zone, I
included a condition for the time zone to correct itself based upon daylight savings time. Then
later when the guestbook displays the username and time of the post, it just echoes the $time
variable and the date/time are displayed with the appropriate time zone notation.
$daylight = gmdate(I);
$zone = 3600*0;
//GMT
$zone = 3600*1;
//CET
if ($daylight = "1")
{
$zone = 3600*-6;
}
elseif ($daylight = "0")
{
$zone = 3600*-7;
}
//USA
$date = gmdate("F jS, Y, g:ia", time() + $zone);
if ($daylight = "1")
{$time = $date . " MDT";
}
elseif ($daylight = "0")
{$time = $date . " MST";
}
When the time is displayed, it shows up something like:
Time: April 7th, 2005, 9:41pm MDT.
Again, thanks and all credit to www.l-serwis.wpt.pl for this function which I've modified only
slightly to meed my specific needs. I hope this is helpful to anyone looking to display local time
on their site.
----
Manual Page -- http://www.php.net/manual/en/function.gmdate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51706
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51706&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51706&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51706&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51706&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51706&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51706&report=yes
Search -- http://master.php.net/manage/user-notes.php