MyBB Community Forums

Full Version: Creating Clocks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been trying to work with PhP but seem to be running into issues.

What I essentially want to do is display the time in a few different time zones to help guild members understand where their peers are.

In short, I want to have the forum display about 5 clocks that could be very different from the forum time.

Example:

01:00 GMT, 20:00 EST, 19:00 CST, 18:00 MST, 17:00 PST

I've been trying:
<?php
echo date("Y/m/d");
echo "<br />";
echo date("Y.m.d");
echo "<br />";
echo date("Y-m-d");
?>

Just as an example. I can't even get that to display. Any thoughts?
This would be cool.. i would be interest as well.
Like, Time Zones From Around The World ..listed on the index.

Good idea!
Here is what I have so far. It works on my server but not on my forum. Also note that the day/month won't update correctly (yet).

<?php
echo date("D\,\ M\ t\ H:i",strtotime("+5 hours"));
echo (" GMT");
echo "<br />";
echo date("D\,\ M\ t\ H:i",strtotime("+2 hours"));
echo (" EST");
echo "<br />";
echo date("D\,\ M\ t\ H:i",strtotime("+1 hours"));
echo (" CST");
echo "<br />";
echo date("D\,\ M\ t\ H:i",strtotime("+0 hours"));
echo (" MST");
echo "<br />";
echo date("D\,\ M\ t\ H:i",strtotime("-1 hours"));
echo (" PST");
echo "<br />";
?>
Technically, it's easier than you think.

When you think about it, timezones are just number of hours difference from GMT (or UTC to be picky). And, you can use php time() to figure that out too...

Say east coast USA is 6 hours behind us in the UK. So that's -6 hours.

$newyork = -6;
$uktime = time();
$difference = $newyork * 60 * 60; // get the amount of seconds difference

$usertime = $uktime + $difference;

$usertime will return a unix time stamp, which you can then use to convert to month/date/time or whatever...

I think - I probably made a mistake somewhere Confused
Well, I've got the code working in vanilla php.

<?php
date_default_timezone_set('UTC');
echo gmdate("D\,\ M\ d\ H:i", strtotime("+2 hours"));
echo (" Test");
echo ('<br />');
echo gmdate("D\,\ M\ d\ H:i");
echo (" GMT");
echo ('<br />');
echo gmdate("D\,\ M\ d\ H:i", strtotime("-5 hours"));
echo (" EST");
echo ('<br />');
?>


All you have to do is change the outputs to the time zone you want. Of course now I need to get it to work on my forum!
One thing to remember is that you can't directly include php in the templates, so you'll have to store your time values in one or more variables and reference the variable(s) in your template.
That is where I get a little hazy; dealing with variables. I'm not a php whiz by any means. So I can do something like this...

$paris = gmdate("D\,\ M\ d\ H:i", strtotime("+1 hours"));

Do I define that variable in global.php?

How do I then place that in the forum template?

($paris)
?
After creating a new template, edit global.php. After unset($admincplink);, add:

$paris = ''; // Is this necessary?
// Do your coding here
	eval("\$paris = \"".$templates->get("paris")."\";");

Then, in your "paris" template (it'll appear in ungrouped templates), put your html. Basic, and probably an easier way to do it, but that's how I did it...