...

View Full Version : Display correct time & date for "gmdate"



bruceleejr
06-19-2010, 06:55 PM
http://www.mujak.com/test/test3.php
I am Mountain Standard Time(MST), Phoenix Arizona but how do I display the correct time~??

As you can see in the "posts" cell the time is incorrect. The last post displays 5:47pm when its 10:47am. Its 7 hours ahead. How do I fix this~??



<div style="position:relative;left:10px;">

<?php
$con = mysql_connect("mujak.com","rootkbc1_muser","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("rootkbc1_halo2x", $con);

$result = mysql_query("SELECT * FROM mybb_posts LEFT JOIN mybb_userfields ON (mybb_posts.uid = mybb_userfields.ufid) WHERE fid=42 ORDER BY pid DESC LIMIT 0,3");

echo "<center><table border=1 bgcolor=white>
<tr>
<th><h3>Subject</h3></th>
<th><h3>Posts</h3></th>
<th><h3>Username</h3></th>
<th bgcolor=#C0CFFA><h1>XBC</h1></th>
<th bgcolor=#C9FFC2><h1>XLK</h1></th>
<th><h3>Team</h3></th>
<th><h3>Console</h3></th>
<th><h3>Location</h3></th>
<th><h3>Bandwidth</h3></th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td style='-moz-border-radius:9px;padding:5px;'bgcolor=#9CDCFF><b>" . $row['subject'] . "</b></td>";
echo "<td style='-moz-border-radius:9px;padding:5px;font-size:10px;'bgcolor=#C9ECFF>" . gmdate("D F j, Y, g:i a", $row['dateline']) . "<br>" . $row['message'] . "</td>";
echo "<td bgcolor=#C9ECFF>" . $row['username'] . "</td>";
echo "<td bgcolor=#C0CFFA>" . $row['fid5'] . "</td>";
echo "<td bgcolor=#C9FFC2>" . $row['fid6'] . "</td>";
echo "<td bgcolor=#C9ECFF>" . $row['fid9'] . "</td>";
echo "<td bgcolor=#C9ECFF>" . $row['fid7'] . "</td>";
echo "<td bgcolor=#C9ECFF>" . $row['fid1'] . "</td>";
echo "<td bgcolor=#C9ECFF>" . $row['fid8'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con)
?>
</div>

DJCMBear
06-19-2010, 07:01 PM
Try this



<?php
date_default_timezone_set('MST');
?>

bruceleejr
06-19-2010, 07:32 PM
Okay I put it like this:


echo "<td style='-moz-border-radius:9px;padding:5px;font-size:10px;'bgcolor=#C9ECFF>" . date_default_timezone_set('MST') . gmdate("D F j, Y, g:i a", $row['dateline']) . "<br>" . $row['message'] . "</td>";


Is this correct~?? If it is, it didn't work. You can check the page now. It came out the same, last post was 6:30pm when it is 11:30am.

DJCMBear
06-19-2010, 11:43 PM
the default timezone is used to set the php date time funcyion to call the right time so it should go at the top of the page in order for the zone to be set over the whole file.

bruceleejr
06-20-2010, 12:17 AM
thats weird its not working

DJCMBear
06-20-2010, 10:56 AM
Take a look here http://www.php.net/manual/en/timezones.php and find the timezone you want.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum