Page 1 of 1

displays time ,but not correct ?

Posted: Thu Mar 11, 2004 11:26 am
by timothye
hello , im not a php man but i am trying to learn , i have a simple problem .i am displaying the time but its 1 hour behind ..

im not sure where the problem is ,since i really dont know much about php.

here is some generic code ..

Code: Select all

<?php 
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);

header("Expires: ".gmdate("D, d M Y H:i:s")."GMT-7000");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
?>
<?php 

//
<?php 
$username = str_replace ("\n"," ", $username);
$username = str_replace ("<", " ", $username);
$username = str_replace (">", " ", $username);
$username = stripslashes ($username);
$p=gmdate("d M H:i");

?>

&output=
<?php 
$date = date( "H:i");
as you can see all the date code but im not sure how to get it to display my time ,its displaying 1 hour behing ..and if i change the "GMT-0700"
it doesnt change a thing ..

thanks

Posted: Thu Mar 11, 2004 11:36 am
by Illusionist
why don't u jsut use the regular date() function to get the time?? Here read this and get the time that way.

Posted: Thu Mar 11, 2004 6:37 pm
by bodge
your server is set in a different time zone - so just add an hour like so:

$timearray = explode (":",$date);
$hour = $timearray[0] + 1; if ($hour==24){$hour=0;}
$newtime = $hour.":".$timearray[1];

Posted: Thu Mar 11, 2004 7:09 pm
by Illusionist
bodge did u look at his code? he is using the gmdate() function which will return the Greenwich Mean Time, and then he is adding the correct offset for his timezone....
If you want to keep using gmdate() then try this:

Code: Select all

<?
$zone=3600*-5;//USA
echo gmdate("h:i",time() + $zone);
?>

Posted: Fri Mar 12, 2004 4:52 am
by bodge
yeah, maybe i only read the last two lines!

Posted: Fri Mar 12, 2004 5:15 am
by Wayne
are you sure the time on the server is correct??