displays time ,but not correct ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
timothye
Forum Newbie
Posts: 15
Joined: Sun Feb 01, 2004 2:36 pm
Location: Sweden/Sverige/USA

displays time ,but not correct ?

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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.
bodge
Forum Newbie
Posts: 7
Joined: Thu Mar 11, 2004 6:13 pm

Post 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];
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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);
?>
bodge
Forum Newbie
Posts: 7
Joined: Thu Mar 11, 2004 6:13 pm

Post by bodge »

yeah, maybe i only read the last two lines!
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

are you sure the time on the server is correct??
Post Reply